-1
$\begingroup$
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.

$\endgroup$
  • 3
    $\begingroup$ This seems more appropriate for stackoverflow. $\endgroup$ – Yuval Filmus Mar 25 '16 at 20:17
1
$\begingroup$

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
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.