in Programming in C edited by
609 views
1 vote
1 vote
for(; i != 0; --i)
{
printf("\nIITM");
--i;
}
  1. If i is initialized to 100, then IITM will be printed 50 times
  2. If i is initialized to 101, then IITM will be printed 51 times
  1. Both I and II are true
  2. I is true, II is false
  3. I is false, II is true
  4. Both I and II are false
in Programming in C edited by
by
609 views

3 Comments

@SPluto in question,  it was i ! =0, not i>0

right? 

0
0
Yes it's i!=0
0
0

@akash.dinkar12 it's i! =0 and the answer will change if it's i!=0

@SPluto

0
0

1 Answer

3 votes
3 votes
Best answer
Only I is true, because in case of I, IITM is printed for every even value of i from 1 to 100, and when i becomes 0 the loop condition is checked, and the loop stops.
But in case of II, the loop condition is checked when i becomes 1, and after that i is decremented to 0 inside the loop, and then the for loop's iterator expression further decrements i to -1. So, the loop condition is not checked when i = 0, it's checked for i = -1, and then the program gets stuck in an infinite loop.
edited by

Related questions