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

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

Test your C++ skills with our quiz based on Bruce Eckel's 'Thinking in C++'. Dive into object-oriented programming, advanced topics, and fundamentals. Perfect for learners and experts alike. Assess your knowledge and become a C++ master!

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.


If a variable is initialized at runtime and is known not to change, what practice is preferred?

  1. Mark it volatile

  2. Mark it const

  3. Mark it static

  4. Mark it extern

The correct answer is: Mark it const

Constants, marked by the "const" keyword, are variables whose values cannot be changed after they are initialized. This is the preferred practice for variables that are known not to change at runtime. Option A, marking the variable "volatile", is incorrect because "volatile" indicates that the value of the variable may change unexpectedly and frequently. Option C, marking the variable "static", is incorrect because "static" variables can still be modified within the scope of their declaration. Option D, marking the variable "extern", is incorrect because "extern" variables are used for referring to variables declared in other source files. It does not match the criteria of a known, unchanging variable initialized at runtime.