hamburger menu
All Coursesall course arrow
adda247
reward-icon
adda247
    arrow
    arrow
    arrow
    What is the default size of an empty class in C++?
    Question



    What is the default size of an empty class in C++?

    A.

    0 bytes

    B.

    1 byte

    C.

    4 bytes

    D.

    8 bytes

    E.

    None of the above

    Correct option is B

    In C++, an empty class has a default size of 1 byte to ensure that each object of the class has a unique memory address, even if it contains no data members.
    Important Key Points:
    1. The size of an empty class ensures that objects of the class can be distinguished in memory.
    2. Adding even one non-static member increases the size beyond 1 byte.
    3. Static members do not contribute to the size of an object because they are shared across all instances.
    Knowledge Booster:
    · Empty Class Size in Java: In Java, objects of empty classes are not explicitly stored, as they are treated differently.
    · Padding in C++: The compiler may add padding for alignment if other members are introduced later.

    test-prime-package

    Access ‘IBPS RRB SO IT Officer (Scale-II)’ Mock Tests with

    • 60000+ Mocks and Previous Year Papers
    • Unlimited Re-Attempts
    • Personalised Report Card
    • 500% Refund on Final Selection
    • Largest Community
    students-icon
    207k+ students have already unlocked exclusive benefits with Test Prime!

    Free Tests

    Free
    Must Attempt

    SBI Clerk Prelims Quant Section Test 01

    languageIcon English
    • pdpQsnIcon35 Questions
    • pdpsheetsIcon35 Marks
    • timerIcon20 Mins
    languageIcon English
    Free
    Must Attempt

    SBI Clerk Prelims English Section Test 01

    languageIcon English
    • pdpQsnIcon30 Questions
    • pdpsheetsIcon30 Marks
    • timerIcon20 Mins
    languageIcon English
    Free
    Must Attempt

    IBPS Clerk Prelims Mock 01

    languageIcon English
    • pdpQsnIcon100 Questions
    • pdpsheetsIcon100 Marks
    • timerIcon60 Mins
    languageIcon English
    test-prime-package

    Access ‘IBPS RRB SO IT Officer (Scale-II)’ Mock Tests with

    • 60000+ Mocks and Previous Year Papers
    • Unlimited Re-Attempts
    • Personalised Report Card
    • 500% Refund on Final Selection
    • Largest Community
    students-icon
    207k+ students have already unlocked exclusive benefits with Test Prime!