The following code
#include <stdio.h>
int main(){
int a = 9;
printf("%d\n", a);
printf("%d, %d, %d\n",a, (a=10), a);
return 0;
}
prints the following output along with the warning
main.c: In function ‘main’:
main.c:8:31: warning: operation on ‘a’ may be undefined
printf("%d, %d, %d\n",a, (a=10), a);
^
main.c:8:31: warning: operation on ‘a’ may be undefined
9
10, 10, 10
Now, I understand that return value of assigning one variable to some value is the value that has been assigned to(Low level details of C/C++ assignment operator implementation. What does it return?.). But interestingly, printing variable 'a' even before assignment is printing 10 instead of 9. Why is it so? It looks like assignment of a is being completed and then all other value is printed. But is it compiler dependent behavior or specified in C, which I didn't find any reference for.