Specify your own integer value for any or all of the enumerators explicitly. - C Data Type

C examples for Data Type:enum

Introduction

Here's how you could define the Weekday type so that the enumerator values start from 1:

The enumerators Monday through Sunday will correspond to values 1 through 7.

Demo Code

#include <stdio.h> 
int main(void) { 
  enum Weekday {Monday = 1, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday};  
  
  enum Weekday today = Wednesday;
    /*w  ww .j ava 2 s  .co  m*/
  printf("Weekday created\n");
  
  printf("%d\n",today);
  
  return 0; 
}

Result


Related Tutorials