+9

Why is the size of an empty class 1 byte?

https://code.sololearn.com/cj4EvGg3dkkK/?ref=app

11/23/2019 5:48:51 AM

Sonic

4 Answers

New Answer

+13

Sonic when an empty class is created In c++ then that contain no string variable or integer but when we create the object of that empty class some memory is assigned for unique address of objects so for that reason 1 byte memory allocation is done for the empty class even if you create an empty function in the empty class then too memory allocation is done 1 byte to that empty class which is allocated for unique adddress identification just an warning will appear of function return nothing which is obvious https://code.sololearn.com/c4et815PLuB7/?ref=app

+8

Sonic hello. Good question.👍 Try this post: https://stackoverflow.com/a/621648/7959868

+6

https://code.sololearn.com/c9jU78Lv3XcK/?ref=app Hope this helps too...

+1

Sonic I do not know the answer but what if you create an object of this class? Will it have no memory allocated?