+ 3

I think the last output must be wrong.Can someone tell me who know about this?

static void Main (string[]args) { int a = 12; int b = ++a * 3; int c = (b++)/4; Console.WriteLine(a+" " +b+" "+c); } The output are : 13 40 9 Why the last output is 9 This's my calculation. a = 12 b = 1+12 * 3 = 39 c = (39 + 1) / 4 = 40/4 = 10 So, the output will be 13 40 10 40/4 = 10, but why 9? I know that the value of b doesn't stop at 39 and it incremented by 1(b++).That's why b is 40.

30th May 2018, 1:31 PM
Mr Thaw
Mr Thaw - avatar
2 odpowiedzi
+ 2
IN PREFIX ++a FIRST a IS INCREMENTED AND THAN EVALUATION TAKE PLACE. IN POSTFIX b++ FIRST EVALUATION IS DONE AND THAN ITS VALUE IS INCREMENTED.
30th May 2018, 1:58 PM
Meet Mehta
Meet Mehta - avatar
+ 24
c = b++ / 4 //here b = 39 after this line b will get incremented .. so c = 39 / 4 = 9 after this line b value will become 40 that's how post increment work https://www.sololearn.com/discuss/489143/?ref=app
30th May 2018, 1:37 PM
🌛DT🌜
🌛DT🌜 - avatar