-3

the answer is coming out to be 45.I cant understand how this thing is working.

main()
{
    int a =10;
    int i =  a++ + ++a + a++ + ++a;
    printf("%d , %d ", i,a);

}

1 Answers1

3

Actually the output is an undefined behavior which is fine.

From the C99 standard are 6.5 Expressions, §2

Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored.

The order of evaluation of the operands is unspecified. If an attempt is made to modify the result of an assignment operator or to access it after the next sequence point, the behavior is undefined.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331