Saturday 16 March 2013

for(;i++;printf("%d",i)) ;


main()
{
int i=0;

for(;i++;printf("%d",i)) ;
printf("%d",i);
}
Answer:
    1
Explanation:
before entering into the for loop the checking condition is "evaluated". Here it evaluates to 0 (false) and comes out of the loop, and i is incremented (note the semicolon after the for loop).


Blog Author: Vijay Kumar

Go to: Java Aptitude


2 comments:

  1. what if we give value of i=1
    then the result is not expected by ur logic ...
    plz explain

    ReplyDelete
  2. I guess If it were 1,then it would be an infinite loop since all the conditions are satisfied?

    ReplyDelete