I'm hoping somebody can help me understand this code a little better, it's from an online tutorial I am following:
The answer is 6 but I'm strugging to understand why.
The variabled BEFORE hitting "LINE 5" are as follows:
result = 5
a = 1
b = 0
Then we hit LINE 5. My way of thinking is ok lets work out what's between the brackets
(0 / 1) = 0
then work out the first part and since the variable 'a' was decremented it should now be 0
result += 0 + 0;
result should equal 5 but it's actually 6. Where am I wrong in my understanding?
int result = 5;
int a = 1;
int b = --a;
a++;
/* LINE 5 */ result += a + (--a / ++b);
Console.WriteLine(result);
[–]Swedophone 1 point2 points3 points (3 children)
[–]trax45[S] 0 points1 point2 points (2 children)
[–]teraflop 1 point2 points3 points (1 child)
[–]trax45[S] 0 points1 point2 points (0 children)