0
Didn't understand something
What is the output of this code? int a = 4; int b = 6; b = a++; Console.WriteLine(++b); The answer is 5, But I don't understand why it's that
4 Réponses
+ 4
Calvin's answer doesn't really explain why.
The increment operator (++) increases the value by one, but depending which side it's on changes whether the increment happens before or after the value is acted on. (evaluated, assigned, etc.)
This is what A++ actually does:
int B = A;
A = A + 1;
This is what ++A does.
A = A + 1;
int B = A;
Or in a single line:
int B = (A = A + 1);
+ 2
b is 4 after b=a++;
b is 5 after ++b
0
Thanks really helped me out
0
It's still hard to understand at sometimes :D.