File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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