Why the sizeof empty class is always 1? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why the sizeof empty class is always 1?

sizeof empty class is 1 in c++

28th Feb 2017, 5:33 PM
Krishna Subhash Sonawane
Krishna Subhash Sonawane - avatar
4 Answers
+ 4
Pointing to the class, compiler needs to know the right address and it just cannot be 0. It is the C++ standard about Classes. If u ask me deeply how the mechanism is working, unfortunately can't help you sir.
28th Feb 2017, 6:05 PM
Patrik Sokol
Patrik Sokol - avatar
+ 3
size 0 is not allowed because of the memory adressing
28th Feb 2017, 5:52 PM
Patrik Sokol
Patrik Sokol - avatar
+ 1
got it sir tysm
28th Feb 2017, 6:06 PM
Krishna Subhash Sonawane
Krishna Subhash Sonawane - avatar
0
can u please explain in detail?how it will happen?
28th Feb 2017, 5:56 PM
Krishna Subhash Sonawane
Krishna Subhash Sonawane - avatar