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.

Free Tests

Free
Must Attempt
Video Solutions

RBI Assistant Pre 2026 Full Mock Test -01

languageIcon English
  • pdpQsnIcon100 Questions
  • pdpsheetsIcon100 Marks
  • timerIcon60 Mins
languageIcon English
Free
Must Attempt
Video Solutions

RBI Asst Prelims 2026 : Reasoning Section Test 01

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

RBI Office Attendant 2026 Full Mock Test - 01

languageIcon English
  • pdpQsnIcon120 Questions
  • pdpsheetsIcon120 Marks
  • timerIcon90 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
354k+ students have already unlocked exclusive benefits with Test Prime!
Our Plans
Monthsup-arrow