Typedef enum

What is the use of typedef enum in a C code???

enum is a integer type; first value in the enum is 0 (unless otherwise specified) second is the first value+1 (0+1 in this case) and so on. When you declare a variable of type enum_data_type, you can only assign it values which exist in the enum…the compiler does the verification. you use enums because the provide a means of changing the values in the ENUM without having to change the code

enum Ranks {FIRST, SECOND};

int main()

{

int data = 20;

if (data == FIRST)

{

  //do something

}

}

sing typedef enum prevents other values being added to the enum:

typedef enum Ranks {FIRST, SECOND} Order;

int main()

{

Order data = 20; //ERROR 20 is not a Order

if (data == FIRST)

{

  //do something

}

}