What is size of a empty class?

Answer Posted / shiv chidambar

size of empty class is 1 byte.
because to indicate class existance in memory 1 byte is
allocated to indicate that class is present.

if the class is empty then there should some kind of
mechanism to indicate or to show this class is present.
if memory (1 byte) not alloacted such a empty class then how
we know that class is present but in programme that class is
written? so for that 1 byte allocated to indicate class
existance.
this happens only for emty classes(Consider example of
tagging interface in java which is empty class).

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What programming language should I learn first?

790


Is c++ a good beginners programming language?

768


Can a class be static in c++?

806


How we can differentiate between a pre and post increment operators during overloading?

821


Name four predefined macros.

793


How do you declare A pointer to function which receives an int pointer and returns a float pointer

878


What is the sequence of destruction of local objects?

716


What is the exit function in c++?

728


Which programming language is best?

744


What do the keywords volatile and mean mutable?

792


What does the following do: for(;;) ; a) Illegal b) Loops forever c) Ignored by compiler...not illegal

918


Differentiate between the message and method in c++?

796


How to declare a pointer to an array of integers?

819


What is c strings syntax?

787


What are advantages of using friend classes?

816