What is size of empty class object

Answers were Sorted based on User's Feedback



What is size of empty class object..

Answer / manish shikarbar

answer is :1

Example:

class Test
{
};

Test Obj;

int size = sizeof(Obj); // answer is 1

Is This Answer Correct ?    9 Yes 1 No

What is size of empty class object..

Answer / kaminee

1

Is This Answer Correct ?    9 Yes 3 No

What is size of empty class object..

Answer / shanky

ans-1.

Is This Answer Correct ?    6 Yes 0 No

What is size of empty class object..

Answer / orvaishnavi

The size of an empty class is 1.
Reason - An object of a class should have unique address.
In order for the object to get unique address, the compiler
inserts a dummy type of size 1(least positive value) into
the empty class so the sizeof the class is returned as 1.

Is This Answer Correct ?    5 Yes 0 No

What is size of empty class object..

Answer / vinay singh

the size of class is nothing until it will not create an object. Class is a template so class object size is determined.So here empty class object size is 1 byte and object is created on managed heap.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

What parameter does the constructor to an ofstream object take?

0 Answers  


How can you specify a class in C++?

0 Answers  


How to allocate memory dynamically for a reference?

0 Answers  


What is a c++ object?

0 Answers  


what is the C++

1 Answers   Wipro,






Why are pointers not used in c++?

0 Answers  


What is encapsulation in c++?

0 Answers  


wrong statement about c++ a)code removably b)encapsulation of data and code c)program easy maintenance d)program runs faster

11 Answers  


What is a driver program?

0 Answers  


How long does it take to get good at leetcode?

0 Answers  


What is anonymous object in c++?

0 Answers  


What is scope of a variable? (LOLZ)

2 Answers   CA, TCS,


Categories