Why sizeof empty enum is size of int | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why sizeof empty enum is size of int

Hi As we know , empty class size is 1 byte, why size of empty enum is not 1 and it's 4 i.e. size of int? It could have been 1 as we used to argue in case of class that one byte is to differentiate memory location of different objects...

1st Jul 2020, 7:25 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
1 Answer
+ 5
Empty enum can be represented with the value 0. As by standards if we don't defined type of enumeration performing over elements than that empty enumeration default value is considered in the range of integers. And being in the range of integer returned size is 4 bytes instead of 1 byte or other. Correct me if I'm missing something but I've read this in past.
1st Jul 2020, 7:36 PM
Preity
Preity - avatar