Mastering C++: A Comprehensive Quiz Based on 'Thinking in C++'

Disable ads (and more) with a membership for a one time $2.99 payment

Prepare for the ultimate C++ challenge with our comprehensive quiz based on 'Thinking in C++'. Test your knowledge with engaging questions and receive instant feedback. Perfect for both beginners and experienced C++ programmers looking to sharpen their skills!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


What is the effect of defining a local variable inside a function as const?

  1. It's a compile-time constant

  2. It prevents changing the variable inside the function

  3. It makes the function const

  4. It ensures the variable is initialized at runtime

The correct answer is: It prevents changing the variable inside the function

Defining a local variable inside a function as const prevents the variable from being changed inside the function. Option A is incorrect because a compile-time constant refers to a value that cannot be changed during compilation, not just within a function. Option C is incorrect because making the function const refers to the function itself, not the local variable inside it. Option D is incorrect because const does not ensure initialization, it only prevents reassignment.