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.


How is a struct in C++ different from a class?

  1. Struct cannot have member functions

  2. Struct defaults to public access, while class defaults to private

  3. Struct cannot inherit from other structs or classes

  4. There is no difference between struct and class in C++

The correct answer is: Struct defaults to public access, while class defaults to private

A struct in C++ and a class in C++ are both data structures that contain data and functions, but they have some differences. A struct defaults to public access for its members, while a class defaults to private. This means that when using a struct, all of its members are accessible from any part of the code, whereas with a class, its data and functions are not accessible from outside of the class unless explicitly declared as public. Option A is incorrect because structs in C++ can actually have member functions, just like classes. Option C is incorrect because structs in C++ can inherit from other structs or classes. Option D is incorrect because there are actually some differences between structs and classes in C++. One of these differences being the default access level, as mentioned in the correct answer.