I have the following code:
#include <stdio.h>
int main()
{
int a = 2, c;
c = a++ + a;
printf("%d\n", c); // prints: 5
}
I thought this would print 4
because the side effect of ++
shouldn't evaluate until the sequence point ;
. However, 5
is printed. I then thought: it must be that +
is a not-very-famous sequence point.
To confirm my previous theory (that +
is a seq. point), I've changed one line:
c = a + ++a; // prints: 6
I thought this would print 5
as the previous case. However, this prints 6
. I've come to the conclusion that I have no idea what's going on here. What am I missing (seems like a lot)?
Compiler version (is this even compiler-dependent?): gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0