But how it calculates the size of object. I mean how it came to know
about a class structure if we use sizeof() to calculate the size of an
user definied class object?
C doesn't use classes - if you've a C++ question, ask it on comp.lang.c++
A C compiler obviously has to know how big objects are, e.g.,
struct thing
{
char c[100];
int n;
};
int main(void)
{
struct thing t;
...
Obviously, the correct amount of space for the auto t has to be allocated -
the compiler's 'seen' struct thing previously, and knows how big it is - so
it can allocate the space ok. So, when you sizeof t, or sizeof struct
thing, you're simply asking the compiler to tell you what it's decided about
the size of an object it already knows about, and to replace sizeof t with a
number which equates to the calculated size.