what is the exact reason ?

please refer the following 2 statements...
1)
int i=1,j;
j= i++ + i++;

2) int i=1,j;
j=++i + ++i;

how j becomes 2 and 6 for the above 2 statements      
respectively ???
\( i guessed j must be 3 and 5\)
Somebody define the exact reason please..   :\( 

-sham-

The effect of the '++' (and all of this applies to '--' as well) operator changes depending on where you put it. If your put it before the variable you're modifying, then the program will increment the variable before using the variable in any sort of statement, thus

 a = \+\+b;

means

 b = b \+ 1;
 a = b;

However, if the operator comes after the variable, then the increment is executed after any expressions the variable is in.

 b = a\+\+;

means

 b = a;
 a = a \+ 1;

The first statement performs all the adding before all the incrementing, so i remains at 1 until after the value is assigned to j.

 j = i \+ i;     // j is 2
 i = i \+ 1;     // i is now 2
 i = i \+ 1;     // i is now 3

The second statement does all the incrementing first, so it adds one to i twice before adding it two itself, and assigning that value to j.

 i = i \+ 1;     // i is now 2
 i = i \+ 1;     // i is now 3
 j = i \+ i;     // j is now 6 \(3\+3\)

If you switched either of the incrementors in either statement to the other side, then you (ought) to get 4.

P.

Well it should be obvious that your compiler is doing all pre-increments before the addition and all post-increments after the addition.

So 2 and 6 are legal values for your code. So would be 3 and 5. Any behavior at all is legal according to the standards. This is because your code is illegal. The standards do not prescribe what the compiler must do with illegal code. In an ideal world, your code would not compile. Once you attach a pre or post increment to a variable it is illegal to reference that variable again until the next "sequence point" (basicly a comma or semicolon).