Which access specifier can be used to make a member of a C++ structure private?
Options
- A. private
- B. protected
- C. Both private and protected
- D. More than one of the above
- E. None of the above
Quiz Practice:
C. Both private and protected
Answer: (C) Both private and protected
A C++ structure is not limited to public members. Although its members are public by default, access specifiers can be explicitly used.
For example:
struct Student {
private:
int marks;
protected:
int rollNo;
};
Therefore, both private and protected members are possible inside a structure.
The important point is that public is only the default; it does not mean that a struct can contain only public members.