Mastering C++: A Comprehensive Quiz Based on 'Thinking in C++'

Disable ads (and more) with a membership for a one time $2.99 payment

Master C++ with our comprehensive quiz based on 'Thinking in C++'. Test your knowledge through flashcards and multiple-choice questions to enhance your understanding of C++. Prepare effectively for your exam!

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 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.