top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to determine size of a class in C++ ?

+4 votes
520 views
How to determine size of a class in C++ ?
posted Oct 18, 2014 by Harshita

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

If I understood your query correctly, your concern is about size of an empty class.
Size of an empty class is 1 byte. It is because if you create two objects of an empty class, there should be at least one byte difference between their addresses. Reason being, sizeof an empty class is not kept as zero.

answer Oct 20, 2014 by Ganesh
Similar Questions
+2 votes

Below is the sample code, Where size of a is not defined at the time of compilation,
Then how compiler knows the size of a? If we run the same program in C then compilation will fail.

#include<iostream>
using namespace std;
main()
{
        string a;
        cin>>a;
        cout<<a;
}
+6 votes
...