0
#import <stdio.h>
int main()
{
    int a,d,b,c;
    a = 10;
    c = 10;
    d = --c + --c+1; 
    b = --a +1+ --a ;
    printf("b= %d, d = %d" , b,d);
    return 0;
}

b= 18, d = 17

the code and it's run

Why d&b are not equal? can you please explain why d=17?

Xiobiq
  • 400
  • 2
  • 7
  • 16

1 Answers1

0

Oh right, it's because it's undefined when the value of a and c will decrement.

d = --c + --c+1; 

If c is decremented twice and then d is calculated, then it gives

d = 8 + 8 + 1 = 17

But if c is decremented as we proceed from left to right, then it gives

d = 9 + 8 + 1 = 18
twasbrillig
  • 17,084
  • 9
  • 43
  • 67
  • Following the equation the way the OP wrote it, `d = --c` (which is 9) `+ --c` (which is 8) `+ 1`; that's why I went in that order. – twasbrillig Nov 13 '14 at 11:13