Question discussion

What is the output of the following code?

359230Medium DSSSB TGT Computer Science 0 replies 0 views
0
What is the output of the following code?
#include <stdio.h>
int main() {
    int i = 5;
    do {
        printf("%d ", i);
        i--;
    } while (i > 5);
    return 0;
}
  • ANo output printed
  • BInfinite loop
  • C5 4 3 2 1
  • D5
Correct answer: D

Explanation

The body of a do-while runs once, printing 5. Then i = 4, and 4 > 5 is false, so the loop ends.

Discussion 0

Nobody has replied yet. Start the discussion!