Thursday, December 01, 2005

What is the Size of Class having a "int" variable and a inline function?

The size of that class is only the size of that int variable. sizeof dont consider the size of Inline functions.


Example:

Class A
{
int IntVariable;
void PrintContent( void )
{
cout << endl << IntVariable << endl;
};
}


Consider size of the word is 4 bytes. So, sizeof( A ) will return 4 bytes only.

2 comments:

Anonymous said...

pinnetega thammbi

Indian Baby said...

size of an empty class/ struct is always equals to a char variable in VC++, int variable in TC++.

Example:

struct MyEmptyStructure
{
};
MyEmptyStructure stTestEmptyStructure;

class MyEmptyClass
{
};

cout << "sizeof ( MyEmptyStructure ) = " << sizeof ( MyEmptyStructure ) << "\n"; // Output in VC++ = 1, in TC++ = 2.

cout << "sizeof ( stTestEmptyStructure ) = " << sizeof ( stTestEmptyStructure ) << "\n"; // Output in VC++ = 1, in TC++ = 2.