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.
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.
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