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.


Which C++ keyword prevents a variable from being modified?

  1. static

  2. const

  3. volatile

  4. extern

The correct answer is: const

The 'static' keyword adjust the storage duration of a variable, meaning that it remains in existence for the duration of the program. The 'volatile' keyword is used for variables that are subject to sudden or unpredictable changes, such as in interrupt service routines. The 'extern' keyword is used to declare a variable that is defined in another file. Option A, 'static', does not prevent a variable from being modified. It adjusts the storage duration of a variable. Option C, 'volatile', is used for a different purpose and does not prevent a variable from being modified. Option D, 'extern', is used to declare a variable that is defined in another file and does not prevent it from being modified. Option B, 'const', is the correct answer because it denotes a variable as a constant and prevents it from being modified.