enum
1 #include <stdio.h> 2 3 enum Color 4 { 5 GREEN = 1, 6 RED, 7 BLUE, 8 GREEN_RED=10, 9 GREEN_BLUE 10 }ColorVal; 11 12 int main(void) 13 { 14 printf("sizeof(ColorVal)=%d\n",sizeof(ColorVal)); 15 printf("GREEN=%d\n",GREEN); 16 printf("RED=%d\n",RED); 17 printf("BLUE=%d\n",BLUE); 18 printf("GREEN_RED=%d\n",GREEN_RED); 19 printf("GREEN_BLUE=%d\n",GREEN_BLUE); 20 return 0; 21 }
operation result:
sizeof(ColorVal)=4 GREEN=1 RED=2 BLUE=3 GREEN_RED=10 GREEN_BLUE=11
enum constant symbols to be variable type wherein the assignment, if an assignment would not be constant from the initial value assigned sequentially +1; if none are assigned, their values sequentially from 0 to +1.