pramod
BAN USER- 0of 0 votes
Answersoutput and why ?
- pramod in India for c++#include<iostream> class con { struct node { int data; int rest; }; public: con() {} }; int main() { con c; std::cout<<"size of con class ="<<sizeof(c); return 0; }
| Report Duplicate | Flag | PURGE
Adobe Software Engineer / Developer C++
output - 4,1
reason -
Class without any data members and member function such type of class is known as empty class. Size of object of empty class is always 1 byte.
When we create object of any class at that time object always gets 3 characteristics i.e.
State
Behaviour
Identity
When we create object of empty class at that time State of that object is nothing. Behaviour of that object is also nothing, but compiler assigns a unique address to that object. Memory in Computer is always organized in the form of bytes and minimum memory available at object address location is 1 byte. That's why size of object of empty class is 1 byte.
answer is one - 1
- pramod August 26, 2012