pre-increment

Post-increment and Pre-increment concept?

假装没事ソ 提交于 2019-11-25 22:26:45
问题 I don\'t understand the concept of postfix and prefix increment or decrement. Can anyone give a better explanation? 回答1: All four answers so far are incorrect , in that they assert a specific order of events. Believing that "urban legend" has led many a novice (and professional) astray, to wit, the endless stream of questions about Undefined Behavior in expressions. So. For the built-in C++ prefix operator, ++x increments x and produces (as the expression's result) x as an lvalue, while x++

How do the post increment (i++) and pre increment (++i) operators work in Java?

廉价感情. 提交于 2019-11-25 21:39:51
问题 Can you explain to me the output of this Java code? int a=5,i; i=++a + ++a + a++; i=a++ + ++a + ++a; a=++a + ++a + a++; System.out.println(a); System.out.println(i); The output is 20 in both cases 回答1: Does this help? a = 5; i=++a + ++a + a++; => i=6 + 7 + 7; (a=8) a = 5; i=a++ + ++a + ++a; => i=5 + 7 + 8; (a=8) The main point is that ++a increments the value and immediately returns it. a++ also increments the value (in the background) but returns unchanged value of the variable - what looks