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.


In C++, casting away constness of a variable is achieved using which keyword?

  1. static_cast

  2. reinterpret_cast

  3. const_cast

  4. dynamic_cast

The correct answer is: const_cast

C++ provides four types of casting - static_cast, reinterpret_cast, const_cast, and dynamic_cast. In this case, the keyword used to cast away constness of a variable is const_cast. Option A, static_cast, performs a general type conversion, option B, reinterpret_cast, converts any pointer into any other pointer type, and option D, dynamic_cast, is used for casting within a class hierarchy. Since none of these options specifically target constness, they are not the correct answer for this question.