+ 3
X++ or ++X
Can anyone explain why this code returns 2 ? https://code.sololearn.com/cc4Fy902dPCN/?ref=app
3 Answers
+ 3
b=++a
here ++a is pre increment operator so it increased the value of a by 1 and assigned to b.
so the value of a and b is now 1
then a+b becomes 2
+ 3
I don't know C#, but I think here is the same case like in Java so I can tell you.
When you write b = ++a, what you basically do is:
b = a + 1 and also you do a = a + 1.
So then the value of both, a and b, is a+1 = 0+1 = 1.
So then a+b = 1+1 = 2.
0
Hi