| Author |
operator precedence
|
uzma Akbar
Ranch Hand
Joined: Sep 21, 2005
Posts: 40
|
|
for (int i = 0; i++ < 2 System.out.print(i); 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 Thanks Uzma
|
 |
Philippe Saint-Just
Greenhorn
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 System.out.print(i); i=0 i<2 true , postfix operator, i value becomes 1, s.o.p executed 1 is priented i=1 i<2 true , postfix operator, i value becomes 2, s.o.p executed 2 is priented i=2 i<2 false
|
 |
 |
|
|
subject: operator precedence
|
|
|