Question 7
Back to Exercise
The program below has a bug. Which statement correctly describes it?
#include <stdio.h>
int main(void) {
int age = 15;
if (age < 18) {
puts("minor");
break;
}
puts("checked");
return 0;
}
- A puts cannot be used in an if
- B break is only allowed inside a loop or a switch, not to leave an if Correct
- C age must be unsigned
- D There is no bug
Correct Answer: Option B
break leaves loops and switches; an if just ends at its closing brace. Use else, or return from the function.
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!