What?
enums are kinda like an easy way to create #defines keywords with values automatically assigned in a sequence which can be specified in a variety of ways. The values must be integer constants like 2 or '2' .
Code:
#include <stdio.h> /* enum-2.c */
int main(void)
{ /* assigned values */
/*enum days{ mon, tue, wed, thu, fri, sat, sun}; 0 1 2 3 4 5 6 */
enum days{ mon = 1, tue, wed, thu, fri, sat, sun }; /* 1 2 3 4 5 6 7 */
int i = 3;
printf("\n mon= %d tue= %d wed= %d thu= %d fri= %d sat= %d sun= %d \n",
mon, tue, wed, thu, fri, sat, sun );
if (i == wed)
printf("It's wednesday \n");
return 0;
}
/****** OUTPUT: **************/
~> gcc -Wall -W -pedantic enum-2.c -o enum-2
~> ./enum-2
mon= 1 tue= 2 wed= 3 thu= 4 fri= 5 sat= 6 sun= 7
It's wednesday