Given the following code:
int a=0,b=2;
printf("(%d,a=%d,a+b=%d)",a=a+3,a,a+b);
why the result is (3,a=3,a+b=5)
Given the following code:
int a=0,b=2;
printf("(%d,a=%d,a+b=%d)",a=a+3,a,a+b);
why the result is (3,a=3,a+b=5)
You are printing the result of an assignment (a=a+3
) which is the assigned value (3
).
But the evaluation order of the parameters depends on the compiler (undefined behaviour). it could print:
(3,a=3,a+b=5)
or:
(3,a=0,a+b=2)
or even:
(3,a=0,a+b=5)