(Created page with "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 increm...")
(No difference)

Revision as of 15:50, 26 July 2014

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.



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