Question 2
Back to Exercise
The program below has a bug. Which statement correctly describes it?
#include <stdio.h>
int main(void) {
int marks = 72;
if (marks >= 40) {
const char *result = "pass";
}
printf("%s\n", result);
return 0;
}
- A marks must be const
- B result is declared inside the if block, so it does not exist after the closing brace Correct
- C printf needs %c
- D There is no bug
Correct Answer: Option B
Block scope ends at the closing brace. Declare result before the if (with a default such as "fail") and assign it inside.
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!