How do structures and classes in C++ differ?

Asked In: BPSC TRE 1.0

Options

  • A. Structures hide every member by default, whereas classes do not
  • B. In structures, members are public by default, whereas in classes, they are private by default
  • C. Structures cannot have private members, whereas classes can
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. In structures, members are public by default, whereas in classes, they are private by default

Detailed Explanation

Correct Answer: Option B

Explanation: Members of a struct are public by default, while members of a class are private by default. Both can contain private, protected, and public members, constructors, member functions, and inheritance.