LearnFrenzy
Sign in Take a free test

C Loops · Predict the Output · Question 3

do-while with a false condition – output Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 3 Back to Exercise

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    int x = 10;
    do {
        printf("%d ", x);
        x++;
    } while (x < 5);
    printf("| %d\n", x);
    return 0;
}
  • A 10 | 11 Correct
  • B | 10
  • C 10 11 | 12
  • D Nothing
Correct Answer: Option A

The body runs once before the condition is checked, printing 10 and making x 11. Then 11 < 5 is false and the loop ends.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links