Let's start with an example:

i = 0;
x = x++;

Will this make x = 0 or x = 1?

We all know the precedence rule and what post increment does (returns the value and then increment the operand). So , lets apply that:

x = (x++);

x = 0; and x will be incremented.

But the problem starts. 

In any text book you would have read till this. But when will x be incremented? Is it immediate? Is it before the next operation is done?

The increment is not done immediately. C specifies certain points before which this (these kinds of side-effects) will be completed. As normally expected all operators in C doesn't form this points (as in the case of Java) and the obvious reason is to make C code run faster. And these points are called "Sequence points" in C.

There is a sequence point after the evaluations of the function designator and the actual arguments but before the actual call. Every evaluation in the calling function (including other function calls) that is not otherwise specifically sequenced before or after the execution of the body of the called function is indeterminately sequenced with respect to the execution of the called function.9

EXAMPLE In the function call (*pf[f1()]) (f2(), f3() + f4()) the functions f1, f2, f3, and f4 may be called in any order. All side effects have to be completed before the function pointed to by pf[f1()] is called.


Accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations are all side effects, which are changes in the state of the execution environment. Evaluation of an expression in general includes both value computations and initiation of side effects.



This work is licensed under the CC By-SA 3.0 , without all the cruft that would otherwise be put at the bottom of the page.

Sister Sites: GATE CSE Wiki, GATE CSE, Aptitude Overflow