Mastering C++: 2025 All-In-One Quiz – Ace 'Thinking in C++' with Comprehensive Practice!

Question: 1 / 565

What happens if you attempt to modify a const variable?

Compiler warning

Compiler error

A A compiler warning will not stop the program from executing, but it is not possible to modify a constant variable, so it would be futile.

C: A runtime error would occur if the program attempted to access or modify a memory location that it does not have permission to, which would not be the case with modifying a const variable.

D: Undefined behavior could potentially occur if attempting to modify a const variable, as different compilers may handle this differently. However, the most common and expected outcome would be a compiler error.

Therefore, the best answer is B: Compiler error, as attempting to modify a const variable is not allowed and will result in a compilation error.

Get further explanation with Examzify DeepDiveBeta

Runtime error

Undefined behavior

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy