Why Result is Different for1)int x=5;int y;y=++x + ++x + ++x2)int x=5;int y=++x + ++x + ++x

Showing Answers 1 - 12 of 12 Answers

machogamer

  • Jan 23rd, 2007
 

In Type 1: Line 3 is treated as an expression, and based on the " Operator Precedence " the increment [ ++ ] operatortakes precedence over summation [ + ] operator. Hence in the expression, the increment operation is done first, and then the summation operation is done, thus the output of the expression will be " 24 ".In Type 2: Line 2 is treated as an assignment statement, and is hence evaluated from left to right. Thus the value of ' y ' in this case will be 21.

  Was this answer useful?  Yes

Remi

  • Feb 27th, 2007
 

How does it sum up to 24?

  Was this answer useful?  Yes

anulekha tewari

  • Oct 6th, 2011
 

24

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions