Short answer:
It will return a copy of var
and then immediately afterwards increment the global var
.
Long answer:
C11 6.5.2.4
"The result of the postfix ++ operator is the value of the operand. As
a side effect, the value of the operand object is incremented..". /--/
The value computation of the result is sequenced before the side effect of
updating the stored value of the operand.
The standard 5.1.2.3 "Program execution" specifies that all side effects must have been evaluated before the program encounters a sequence point. (Plenty of into about sequence points can be found here).
There is a sequence point after a return
statement (C11 6.8/4).
This means that the expression var++
is guaranteed to be completely evaluated before any code in main() continues.
Your machine code will look like this pseudo code:
- Store a local copy of
var
on the stack (or in a register etc)
- Increase the global
var
with 1.
- Return from sub routine.
- Use "copy-of-
var
".
Had you used prefix increment instead, the increase operation would have been sequenced before the copy was stored.