Multiple choice

What is the output of the following C code?

#include<stdio.h> int main() { short int i=0; for(i;++i;i>=99) printf(%d,i); return 0; }

  1. Infinite loop

  2. 1 to 32767 and then from -32768 to -1

  3. Compiler error

  4. Print from 1 to 99

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Let Initial value be: i It does not affect any thing in the program. Checking condition: ++i It is incrementing the value of i by one in each iteration.  We know in c, zero means false. When value of i is zero, loop will terminate. Increment value: i >= 99 It is not incrementing the value of variable i.

It is clear, loop will terminate when value of variable i is zero. Hence, printf function will print: 1 to 32767 and then, from -32768 to -1   (range of short int) Hence, this option is correct.