How can i know the size of the enum Days? Will it be equal to 7*4(sizeof(int)) = 28 ??
The printf() here is giving me value 4, How can it be explained?
enum Days
{
saturday,
sunday ,
monday ,
tuesday,
wednesday,
thursday,
friday
} TheDay;
printf("%d", sizeof(enum Days));
Also we can use this as (enum Days)(0), which is similar to the integer array.If size is equal to 4 then how this array kind of behavior can be explained ?
In C all enums are most of the time integers of type
int, which explains whysizeof(Days) == 4for you.To know how many values are in an
enumyou can do something like this:Then
NUM_DAYSwill be the number of enumerations inDays.Note that this will not work if you change the values of an enumeration, for example:
In the above enum,
NUM_FOOwill be6.