Why size of operator is showing 12 bytes instead of 9 for the below code in c++. As int occupies 4 bytes, float occupies 4 bytes and character occupies 1 byte, then sizeof should give 9 bytes as output instead of 12.
Object stores memory for data members only not member functions (methods).
#include <iostream>
using namespace std;
class Sample{
public :
int i;
float a;
char ch;
public:
Sample(int j, float b, char dh){
i=j; a=b; ch=dh;
}
};
int main(){
Sample s1(10,3.14f, 'A');
Sample s2(20,6.28f,'B');
cout<<sizeof(s1)<<endl;
cout<<sizeof(s2)<<endl;
return 0;
}