What is the purpose of a class declaration in C++?
Options
- A. To define a user-defined type
- B. To declare only integer variables
- C. To execute the program automatically
- D. More than one of the above
- E. None of the above
Quiz Practice:
A. To define a user-defined type
Answer: (A) To define a user-defined type
A class is a mechanism in C++ for creating a user-defined data type.
A class can combine data and functions that operate on that data into one unit.
For example:
class Student {
int marks;
};
This creates a user-defined type named Student.