Ace Your C++ Skills 2026 – Rock the ‘Thinking in C++’ Challenge!

1 / 565

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

Struct cannot have member functions

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.

Get further explanation with Examzify DeepDiveBeta

Struct cannot inherit from other structs or classes

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

Next Question
Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy