sizeof an object | SoloLearn: Learn to code for FREE!

0

sizeof an object

class A {} int main { A a; cout << sizeof(a); // outputs 1 Why is this the case? Are we evaluating the object name as a char?

7/26/2020 7:13:25 AM

Solus

2 Answers

New Answer

+8

Each object is given different address. So to distinguish different objects, size of each empty class object is 1 byte i.e. minimum memory allotted as per C++ standards. Some useful answers, you can get here: https://stackoverflow.com/questions/2362097/why-is-the-size-of-an-empty-class-in-c-not-zero

0