+ 5
How does it work?
What is the output of this code? int x = 9; x += ++x; Console.Write(x); //What is the valid output? This was in the C# challenge. I entered 20 and I was wrong!!
4 Antworten
+ 2
The correct answer is 19.
The program first places the value of x in the left hand side and then adds to it the incremented value. It will look like this at the end:
9 += ++9;
(= 19)
+ 17
Wouldn't it be 19?
9 + (1+9) => 9+10 = 19
+ 6
Ok! I was confused because it was pre-increment so I thought x will first increase then assigned. I got it now. Thanks! 😊😉😊
+ 3
The answer is 19:
Let's simplify the statement to:
int x = 9;
x=x+(++x);
which means:
x=9+(10)=19