edited by
615 views
1 votes
1 votes
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
edited by

1 Answer

Best answer
3 votes
3 votes
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

0 votes
0 votes
1 answer
1
SPluto asked May 2, 2019
563 views
Let L1 and L2 be 2 languages which are not regular. Which of these is true?The union of L1 and L2 is not regular.The intersection of L1 and L2 is not regular.Both I and I...
0 votes
0 votes
0 answers
2