World's most popular travel blog for travel bloggers.

Why does this statement evaluate to 176?

, , No Comments
Problem Detail: 
int y = 10; int z; z = (++y * (y++ + 5)); // Evaluates to 176 

According to me this should evaluate to 180. Please provide an explanation as well which relates to precedence and associativity.

Asked By : Shreeyash Gotmare
Answered By : stephenwebber

Here's a link to how increment works.

Here's how the above problem evaluates:

z = (++y * (y++ + 5)); // Beginning expression z = (11 * (y++ + 5)); // y -> 11, 11 is used as a value z = (11 * (11 + 5)); // 11 is used as value, y -> 12 z = (11 * 16); // Evaluation z = 176; // Evaluation 
Best Answer from StackOverflow

Question Source : http://cs.stackexchange.com/questions/54936

3200 people like this

 Download Related Notes/Documents

0 comments:

Post a Comment

Let us know your responses and feedback