# C Enumerated Types

> Learn how to create enumerated types in C with the typedef and enum keywords, defining a type that can hold one of a fixed set of values like weekdays.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2020-02-27 | Topics: [C](https://flaviocopes.com/tags/clang/) | Canonical: https://flaviocopes.com/c-enums/

Using the [`typedef`](https://flaviocopes.com/c-typedef/) and `enum` keywords we can define a type that can have either one value or another.

It's one of the most important uses of the `typedef` keyword.

This is the syntax of an enumerated type:

```c
typedef enum {
  //...values
} TYPENAME;
```

> The enumerated type we create is usually, by convention, uppercase.

Here is a simple example:

```c
typedef enum {
  true,
  false
} BOOLEAN;
```

C comes with a [`bool` type](https://flaviocopes.com/c-boolean/), so this example is not really practical, but you get the idea.

Another example is to define weekdays:

```c
typedef enum {
  monday,
  tuesday,
  wednesday,
  thursday,
  friday,
  saturday,
  sunday
} WEEKDAY;
```

Here's a simple program that uses this enumerated type:

```c
#include <stdio.h>

typedef enum {
  monday,
  tuesday,
  wednesday,
  thursday,
  friday,
  saturday,
  sunday
} WEEKDAY;

int main(void) {
  WEEKDAY day = monday;

  if (day == monday) {
    printf("It's monday!");
  } else {
    printf("It's not monday");
  }
}
```

Every item in the enum definition is paired to an integer, internally. So in this example `monday` is 0, `tuesday` is 1 and so on.

This means the conditional could have been `if (day == 0)` instead of `if (day == monday)`, but it's way simpler for us humans to reason with names rather than numbers, so it's a very convenient syntax.
