Question 4
Back to Exercise
The program below has a bug. Which statement correctly describes it?
#include <stdio.h>
int main(void) {
int n = 3;
do {
printf("%d ", n);
n--;
} while (n > 0)
printf("\n");
return 0;
}
- A do-while needs a for header
- B A do-while statement must end with a semicolon after the condition Correct
- C n-- must come before printf
- D There is no bug
Correct Answer: Option B
Unlike while and for, a do-while ends with while (condition);. Without the semicolon the compiler reports a syntax error.
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!