@piyushh, see there is a difference in pre-increment and post-increment.

The pre-increment operator 'tells' compiler that increment the value first and then use it.

The post increment operator 'tells' compiler that use the same value through out and then use it.

So I am assuming that you derived that answer using following technique.

value of a is 1,b is 1,c is 1

p= a++ + b++ || c++ + ++a ;

p = a++ + b++ || c++ + ++a

p = 1 + 1 || 1 + 2

p = 2 || 3

p = 1.

Now post increment value of a, so now a is 3.

But then this way of analyzing will lead to an incorrect answer as there is a boolean operator || (Logical OR). Logical operator is a short circuit operator.

It means that it will check for the first condition, if its true then it will not bother to check the other condition, if its false, then only it will check the other condition.

So in this case,c++ + ++a will never be executed.

Now let us analyze the code again.

p = a++ + b++ || c++ + ++a

p = 1 + 1 ||

p= 2||(this is not 0, hence overall statement is true or 1.)

therefore p=1.

Now post increment the value of a, now a=2.

Thus we get p=1 and a=2.