Underlying type

Enumerations

//C23: the underlying type goes after a colon
enum Season : char {
    Summer = 'A', Fall, Winter, Spring
};

enum Align : unsigned char {
    Left, Right, Center
};

char fall = Fall;
//fall is 'B'

unsigned char center = Center;
//center is 2

size_t alignSize = sizeof(enum Align);
//alignSize is 1

//without a colon the compiler picks the type, here int
enum Color {
    Red, Green, Blue
};
size_t colorSize = sizeof(enum Color);
//colorSize is 4

printf("fall is %c\n", fall);
printf("center is %d\n", center);
printf("alignSize is %zu\n", alignSize);
printf("colorSize is %zu\n", colorSize);