0
int a = 4; int b = 6; b = a++; Console.WriteLine(++b); == 6?
int a = 4; int b = 6; b = a++; Console.WriteLine(++b); shouldn't the output of this be 6? b = a++, since a is 4 and you add 1 to it it's 5 and "Console.WriteLine(++b)" adds one more? Am I really that retarded? >_> pls some1 enlighten me about why this is 5
6 Answers
+ 13
When you see a++ it means we use the value of a and then a increments.. So b = a++ means that we assign a to b and only after that the value of a increments.. so after the line b = a++, b becomes 4 and a becomes 5.. ++b means we should add 1 to the value of b before using it's value.. so b becomes 5 and the output is 5.
+ 6
A is 4. B is 6. You set B's value to A's value and then incremented A. A is now 5. B is now 4. You increment B and then print it to the screen. A is 5. B is 5.
+ 1
a++ first assigns the value and then increments the value of a whereas ++a first increments the value of a and then assigns it.
+ 1
i think, in this question, we should know, the difference between varibale++, and ++variable.
b=a++, the program
b is now 4, after that a is 5,
++b ==> b=b+1; we know, b was 4, we put the value, b = 4+1; so b = 5;
0
Ä°nt a = 4
Ä°nt b = 5
a=b
what is a variable
0
Ä°nt a = 4;
Ä°nt b = 5;
b=a;
What is a variable