Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22091

Is binary operator '+' a sequence point in C? [duplicate]

$
0
0

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


Viewing all articles
Browse latest Browse all 22091

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>