#include<iostream>
using namespace std;
class Prac{
string ch;
public:
void getstring(string g)
{
ch=g;
return;
}
};
int main()
{
Prac obj1;
Prac obj2;
string str1;
cout<<"Enter string for object 1"<<endl;
getline(cin,str1);
obj.getstring(str1);
cout<<sizeof(obj1)<<endl;
cout<<sizeof(obj2)<<endl;
return 0;
}
We know that the size of the object is the total size of the data members present in it. Here for the obj1 we are inserting some value for the string variable and for obj2 we are leaving it blank. Why won't there be any difference in the output(size of the objects)?