Question 1
Back to Exercise
The program below has a bug. Which statement correctly describes it?
#include <stdio.h>
int main(void) {
const int max_attempts = 3;
max_attempts = 5;
printf("%d\n", max_attempts);
return 0;
}
- A const variables must be global
- B max_attempts is const, so it cannot be assigned after its initialisation Correct
- C printf cannot print a const
- D There is no bug
Correct Answer: Option B
A const object gets its value only from its initializer. If the value really must change, the variable should not be const.
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!