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 keyword 'protected' do in the context of C++ structures?

  1. It makes members accessible only within the struct and its children

  2. It encrypts the struct members

  3. It makes members globally accessible

  4. It hides the struct from the compiler

The correct answer is: It makes members accessible only within the struct and its children

The keyword 'protected' in C++ structures makes its members accessible only within the struct and its child objects. This means that the members cannot be accessed from outside the struct or from unrelated classes. This protects the data within the struct from being modified or accessed accidentally by other parts of the program. Option B is incorrect because 'protected' does not encrypt the struct members. Option C is incorrect because it does not make members globally accessible, unlike the 'public' keyword. Option D is incorrect because 'protected' does not hide the struct from the compiler, it only limits its accessibility.