0

Can someone help me to understand this code

int a = 4; int b = 6; b = a++; Console.WriteLine(++b); The output is 5 I just can’t workout how it gets that output

17th Jan 2019, 3:11 AM
Sidian
Sidian - avatar
6 Answers
+ 3
Sham XR you're confusing pre with post b= a++ is b =4, a =5 and ++b = 5
17th Jan 2019, 3:48 AM
Vaas
Vaas - avatar
0
a=4 b=6 b=a++ = 4++= 5.
17th Jan 2019, 3:30 AM
Ahmad Ali
Ahmad Ali - avatar
0
console. writeLine(++b) = ++5 =5
17th Jan 2019, 3:31 AM
Ahmad Ali
Ahmad Ali - avatar
0
the program execute the expression from right to left. a=4++ means 1+4=5 but a =++4 means 4+nothing =4
17th Jan 2019, 3:35 AM
Ahmad Ali
Ahmad Ali - avatar
0
thanks I understand it now I had trouble with it because of the b = 6
17th Jan 2019, 3:53 AM
Sidian
Sidian - avatar
0
i myself confused because he said the answer is 5
17th Jan 2019, 5:38 AM
Ahmad Ali
Ahmad Ali - avatar