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.


Which access specifier must follow the struct member declarations it applies to?

  1. It doesn't need to follow, it's applied globally

  2. private

  3. Before and after

  4. All access specifiers need to be mentioned at the start

The correct answer is: private

Unlike classes, structs in C++ have default public access, which means all the member declarations are accessible by any part of the program. Therefore, it is important to explicitly specify the access specifier for struct members to control their accessibility. Using the "private" access specifier specifies that the member can only be accessed by member functions or friends of the struct. Both options A and D are incorrect as they suggest that access specifiers are not necessary or must be mentioned for all members, respectively. Option C is also incorrect as it does not specify which access specifier needs to follow the struct member declarations.