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 are the conditions that have to be met for a condition to be an invariant of the class?

1 Answers  


If you don’t declare a return value, what type of return value is assumed?

0 Answers  


catch(exception &e) { . . . } Referring to the sample code above, which one of the following lines of code produces a written description of the type of exception that "e" refers to? a) cout << e.type(); b) cout << e.name(); c) cout << typeid(e).name(); d) cout << e.what(); e) cout << e;

2 Answers   Quark,


Why can’t you call invariants() as the first line of your constructor?

0 Answers  


Design a program to input a date from user in the form day/month/year (e.g. 2/6/2000) and report whether it’s a valid date or not. The program should take account of leap years. You will need to know that a leap year is a year that is exactly divisible by 4, except that century years are only leap years if they are divisible by 400.

1 Answers  






in C++ , the word plus plus who found this?

4 Answers  


What are the uses of pointers?

0 Answers  


What is c++ map?

0 Answers  


In java a final class is a class that cannot be derived. How can you make a similar class in C++

1 Answers  


To what does “event-driven” refer?

0 Answers  


What is the difference between mutex and binary semaphore?

0 Answers  


Explain unexpected() function?

0 Answers  


Categories