C | Loops & Control Structure | Question 8

filter_none

edit
close

play_arrow

link
brightness_4
code

#include<stdio.h>
int main()
{
   int n;
   for (n = 9; n!=0; n--)
     printf("n = %d", n--);
   return 0;
}

chevron_right


What is the output?
(A) 9 7 5 3 1
(B) 9 8 7 6 5 4 3 2 1
(C) Infinite Loop
(D) 9 7 5 3


Answer: (C)

Explanation: The program goes in an infinite loop because n is never zero when loop condition (n != 0) is checked. n changes like 7 5 3 1 -1 -3 -5 -7 -9 …



My Personal Notes arrow_drop_up