tags:

views:

132

answers:

4

Why do C enumeration constants need a name? Because this:

#include <stdio.h>

enum {NO, YES};

int main(void)
{
    printf("%d\n", YES);
}

works just the same as this:

#include <stdio.h>

enum boolean {NO, YES};

int main(void)
{
    printf("%d\n", YES);
}
+8  A: 

So that you can create variables of the enumeration type:

enum boolean read_file = NO;
anon
+1  A: 

Well, you might want to define a function like this:

void here_is_my_answer(boolean v)
{
   if (v == YES) { 
   } else {
   {
}
bmargulies
+6  A: 

If you want to create a type that is 'of the enum', such as:

enum boolean x;
x = NO;

The easier way to do this is with a typedef:

typedef enum {NO, YES} boolean;

And then all you have to do is use boolean as the type:

boolean x;
x = NO;
Kris
+2  A: 

If I'm understanding you right you're simply using an example that is too basic.

Days of the week is a good example of enums.

McAden