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
Joined: Dec 07, 2005
i++ increments i after it has been evaluated. ++i increments it before it's evaluated.
Joined: Oct 15, 2005
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