What is size of a empty class?

Answers were Sorted based on User's Feedback



What is size of a empty class?..

Answer / ravi

one

Is This Answer Correct ?    25 Yes 2 No

What is size of a empty class?..

Answer / dips

it doesnot take memory just writing class in C++
means i want to say
class d{};
no memory allocation is done here
but is this a empty class?

Is This Answer Correct ?    13 Yes 2 No

What is size of a empty class?..

Answer / ilana

why ?

Is This Answer Correct ?    6 Yes 0 No

What is size of a empty class?..

Answer / sourisengupta

1 Byte.

Is This Answer Correct ?    4 Yes 0 No

What is size of a empty class?..

Answer / ganesh

when ever an datamember is not the part of the class then default value for object size is 1 byte.
but if int a;
char c;
then it will consume 3 bytes .........

Is This Answer Correct ?    2 Yes 0 No

What is size of a empty class?..

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

What is size of a empty class?..

Answer / mashal

Size of an empty class is 1 byte. It is non zero to ensure that the two different objects will have different addresses.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

What is the use of setfill in c++?

0 Answers  


What is type of 'this' pointer? Explain when it is get created?

0 Answers  


What is a try block?

0 Answers  


What are the two types of comments, and how do they differ?

0 Answers  


Can recursive program be written in C++?

0 Answers  






How to declare a function pointer?

0 Answers  


find the two largest values among the 6 numbers using control structures : do-while,for,if else,nestedif- else ,while. one or two of them.

0 Answers  


In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest.

5 Answers   GE,


Why we use #include iostream in c++?

0 Answers  


Can there be at least some solution to determine the number of arguments passed to a variable argument list function?

0 Answers  


What is double in c++?

0 Answers  


Define pure virtual function?

0 Answers  


Categories