jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes operator precedence 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 precedence" Watch "operator precedence" New topic

operator precedence

uzma Akbar
Ranch Hand

Joined: Sep 21, 2005
Posts: 40
for (int i = 0; i++ < 2

Can anyone explain that why the output is 12. Why the 2 get printed as it should be rejected at the check and also ++ operator has higher precedence as compared to < so isn't that i is incremented first and then checked for the value.?

Please help as it sounds quite easy but sometimes easy ones are tricky
Philippe Saint-Just

Joined: Dec 07, 2005
Posts: 15
i++ increments i after it has been evaluated.
++i increments it before it's evaluated.
Naresh Gunda
Ranch Hand

Joined: Oct 15, 2005
Posts: 163
for (int i = 0; i++ < 2

i<2 true , postfix operator, i value becomes 1, s.o.p executed 1 is priented

i<2 true , postfix operator, i value becomes 2, s.o.p executed 2 is priented

i<2 false
I agree. Here's the link: http://aspose.com/file-tools
subject: operator precedence
It's not a secret anymore!