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.


What C++ keyword is used to ensure a variable retains its value between function calls?

  1. const

  2. static

  3. volatile

  4. register

The correct answer is: static

A const keyword is used to designate a variable as constant and its value cannot be changed. This would not retain the variable's value between function calls. A volatile keyword is used for variables whose value can be changed by external factors and is used for multithreading purposes but would not ensure value between function calls. A register keyword is used to suggest to the compiler to store a variable in a register for optimization but does not ensure the value between function calls. A static keyword is used to retain the value of a variable between function calls and is the correct answer.