Question 1
Back to Exercise
The program below has a bug. Which statement correctly describes it?
#include <stdio.h>
int main(void) {
total = 10;
int total;
printf("%d\n", total);
return 0;
}
- A total must be global
- B total is used before its declaration; a name is only visible after the point where it is declared Correct
- C printf needs %ld
- D There is no bug
Correct Answer: Option B
Scope begins at the end of the declarator, so the first line refers to an undeclared name. Declare (and initialise) before use: int total = 10;.
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!