• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

operator confusion

 
Gary Laird
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could someone please help me on this?

Heres the question, taken from Page 65 of Mughal and Rasmussen Book

int k = 1;
int i = ++k + k++ + + k;

Their evaluation is ((++k) + (k++)) + (+k) -> ((2) + (2) + (3))) = 7

Now on page 42, they give you the operator precedence table

Postfix Operators [] . parameters exp++ exp--
Unary Prefix operators ++exp --exp +exp -exp ~ !

To be, that means that the 2nd k in the expression should be evaluated first.(k++) giving a value of 1.

What am I missing here?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try reading this and this.
 
Gary Laird
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nice one thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic