sizeof an object | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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?

26th Jul 2020, 7:13 AM
Solus
Solus - avatar
2 Answers
+ 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
26th Jul 2020, 7:23 AM
Nova
Nova - avatar
0
yes!
26th Jul 2020, 8:18 AM
hodaya mazluminyan
hodaya mazluminyan - avatar