This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes operator confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "operator confusion" Watch "operator confusion" New topic
Author

operator confusion

Gary Laird
Greenhorn

Joined: Mar 26, 2004
Posts: 3
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?


gazman
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Try reading this and this.


SCJP Tipline, etc.
Gary Laird
Greenhorn

Joined: Mar 26, 2004
Posts: 3
nice one thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: operator confusion
 
Similar Threads
question from Khalid book
Operator precedence
Operator Precendence
Operators - Mughal p.56 Ques 3.7
Operator precedence