Question 9
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int i = 1;
again:
printf("%d ", i);
i *= 2;
if (i < 20)
goto again;
printf("\n");
return 0;
}
- A 1 2 4 8 16 Correct
- B 1 2 4 8 16 32
- C 2 4 8 16
- D 1 2 4 8
Correct Answer: Option A
The backward goto behaves like a do-while: print, double, repeat while i < 20. After 16, i becomes 32 and the jump is not taken. A real loop would express this more clearly.
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!