Question discussion

What will be the output of the following C code?

358863Medium DSSSB TGT Computer Science 0 replies 0 views
0
What will be the output of the following C code?
#include <stdio.h>
int main()
{
    int i = 1;
    while (i < 5) {
        printf("%d ", i++);
        i++;
    }
    return 0;
}
  • A2 4
  • B1 3 4
  • C1 3
  • D1 2 3 4 5
Correct answer: C

Explanation

i = 1 prints 1, then i becomes 2 and then 3. Next 3 is printed, and i becomes 4 and then 5, so the loop ends. The output is 1 3.

Discussion 0

Nobody has replied yet. Start the discussion!