O
openbysource
I wrote this program:
#include <iostream>
using namespace std;
class sample
{
private:
int age;
float salary;
char status;
};
int main()
{
sample s1;
cout << "sizeof int = " << sizeof(int) << endl;
cout << "sizeof float = " << sizeof(float) << endl;
cout << "sizeof char = " << sizeof(char) << endl;
cout << "sizeof sample class = " << sizeof(sample) << endl;
cout << "sizeof sample class object = " << sizeof(s1) << endl;
return 0;
}
Got this strange output:
sizeof int = 4
sizeof float = 4
sizeof char = 1
sizeof sample class = 12
sizeof sample class object = 12
Isn't it strange. I am using GCC 4.1.1. Isn't it should be 9 for the
last two one.
Please help.
Regards
#include <iostream>
using namespace std;
class sample
{
private:
int age;
float salary;
char status;
};
int main()
{
sample s1;
cout << "sizeof int = " << sizeof(int) << endl;
cout << "sizeof float = " << sizeof(float) << endl;
cout << "sizeof char = " << sizeof(char) << endl;
cout << "sizeof sample class = " << sizeof(sample) << endl;
cout << "sizeof sample class object = " << sizeof(s1) << endl;
return 0;
}
Got this strange output:
sizeof int = 4
sizeof float = 4
sizeof char = 1
sizeof sample class = 12
sizeof sample class object = 12
Isn't it strange. I am using GCC 4.1.1. Isn't it should be 9 for the
last two one.
Please help.
Regards