Sizeof Thi sclass..

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Wh is the size of this class.......................
class Bas

public
int T
}
class Child : public Bas

public
double T
}
int main(int argc, char* argv[]

Child T
printf("%d \n",sizeof(T))
return 0

Im getting 16 as ans (VC++ Compiler
Why
Regards Balamurali c
 
Balamurali said:
Wh is the size of this class........................
class Base
{
public:
int T;
};
class Child : public Base
{
public:
double T;
};
int main(int argc, char* argv[])
{
Child T;
printf("%d \n",sizeof(T));
return 0;
}
Im getting 16 as ans (VC++ Compiler)
Why ?

4 bytes for an int, 4 bytes for alignment (so double comes on 8-byte
boundary) and 8-bytes for a double.

If you'd like to eliminate the alignment padding, see #pragma pack in the VC
documentation.

-cd
 
Back
Top