What is size of empty class object

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the disadvantage of using a macro?

813


What is std :: endl?

793


What are smart pointers?

1246


Differentiate between an inspector and a mutator ?

914


Are vectors faster than arrays?

780


What are virtual functions in c++?

914


Does a derived class inherit or doesn't inherit?

837


How can an improvement in the quality of software be done by try/catch/throw?

824


Does c++ vector allocate memory?

744


What is the insertion operator and what does it do?

804


Can I have a reference as a data member of a class? If yes, then how do I initialise it?

935


Can you sort a set c++?

776


What is the difference between global variables and local variable

735


Is c++ double?

761


When should we use container classes instead of arrays?

807