Question about post-increment | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Question about post-increment

Hey! I got the following answer in the quiz: int x = 1; x += x++; System.out.println(x); x is 2 in the end. My question: 1 += 1++; Shouldn't the post-increment be added now? Inbetween the calculation and out.print? So the result should be 3?

8th Dec 2019, 5:06 PM
Philipp Hofmann
1 Answer
0
I would say that this expression is undefinded. An example with two variables: int x = 1; int y = 1; y += x++ first add value of x to y -> y is now 2 than increment x -> x is now 2
8th Dec 2019, 5:54 PM
Denise Roßberg
Denise Roßberg - avatar