Question 1
Back to Exercise
What happens with const int x = 5; x = 6;?
- A x becomes 6
- B A compile error: x is read-only Correct
- C x stays 5 silently
- D A run-time crash
Correct Answer: Option B
The compiler rejects any assignment to a const-qualified object ("cannot assign to variable 'x' with const-qualified type"). A const object gets its value only from its initializer.
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!