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!

Practice this question and more.


What does the 'new' keyword do in C++?

  1. Defines a new namespace

  2. Allocates memory dynamically

  3. Declares a new type

  4. Updates a variable to its latest value

The correct answer is: Allocates memory dynamically

The 'new' keyword in C++ is used to dynamically allocate memory for a variable or an object. This means that the memory for the variable or object is allocated at runtime, rather than at compile time like with statically allocated variables. Choosing option A, C, or D would be incorrect because all of these options do not accurately describe the purpose of the 'new' keyword. Option A refers to defining a namespace which is unrelated to memory allocation. Option C refers to declaring a new type which also does not involve memory allocation. And option D refers to updating a variable to its latest value which is not related to memory allocation at all. Therefore, the only correct answer is option B which accurately describes the purpose of the 'new' keyword in C++.