What will happen if in a C++ program, a class has no name?

2023

What will happen if in a C++ program, a class has no name?

  1. A.

    It is not even allowed in C++

  2. B.

    It will not have the constructor

  3. C.

    It will not have the destructor

  4. D.

    More than one of the above

  5. E.

    None of the above

Attempted by 197 students.

Show answer & explanation

Correct answer: A

In C++, a class must have a name to be declared. An unnamed class is not allowed in standard C++ syntax. This is because the class name is required for object creation, type definition, and memory allocation. Without a name, the class declaration is invalid and will result in a compilation error.

हिन्दी उत्तर: C++ में, एक क्लास को नाम होना आवश्यक होता है। अनाम क्लास C++ में अनुमति नहीं है। यह इसलिए है क्योंकि क्लास का नाम ऑब्जेक्ट बनाने, प्रकार परिभाषा और मेमोरी आवंटन के लिए आवश्यक होता है। नाम के बिना, क्लास घोषणा अमान्य होती है और कंपाइलेशन त्रुटि का कारण बनती है।

Explore the full course: Uppsc Polytechnic Lecturer 2025 Cs