LearnFrenzy
Sign in Take a free test

C Const · const MCQ · Question 1

const int x = 5; x = 6; – what happens? Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links