Which of the following can be declared inside a C++ structure?
Options
- A. Only data members
- B. Only member functions
- C. Both data members and member functions
- D. More than one of the above
- E. None of the above
Quiz Practice:
C. Both data members and member functions
Answer: (C) Both data members and member functions
Unlike a traditional C structure, a C++ structure can contain both data members and member functions.
For example:
struct Student {
int marks;
void show() { cout << marks; }
};
Here, marks is a data member and show() is a member function.
This is one reason why C++ structures are more powerful than the structures available in the C language.