# Enum

## Enumeration

**Enumeration** (aka Enum): User-defined data type for assigning names to constants, so the code becomes more legible.

> We will use `UPPER_SNAKE_CASE` most of the time for enums.

```c
enum week {
    SUNDAY, 
    MONDAY, 
    TUESDAY, 
    WEDNESDAY, 
    THURSDAY, 
    FRIDAY, 
    SATURDAY
};
/**
 * SUNDAY corresponds to 0
 * MONDAY corresponds to 1
 * ...
 * SATURDAY corresponds to 6
 * /
```

#### Sample Code

```c
#include <stdio.h> 

enum week {
    SUNDAY, 
    MONDAY = 0, 
    TUESDAY = 3
};
  
int main() { 
   printf("%d, %d, %d\n", sunday, monday, tuesday); 
   return 0; 
}
```

Output:

```
0, 0, 3
```

You can also declare enum variables.

```c
// creating an enum variable called `day` of type `week`

enum week {
    SUNDAY, 
    MONDAY, 
    TUESDAY
} day;

/*--- OR ---*/

enum week {
    SUNDAY, 
    MONDAY, 
    TUESDAY
};
enum week day;
```

#### Sample Code

```c
#include <stdio.h> 
  
enum week {
    SUNDAY, 
    MONDAY = 3, 
    TUESDAY
}; 
  
int main() { 
    enum week day; 
    day = tuesday; 
    printf("%d\n", day); 
    return 0;
}
```

Output:

```
4
```

Enums are useful when we want to define multiple variables which can be grouped together.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hkust-robotics-team.gitbook.io/hkust-robotics-team-software-tutorial/tutorial/tutorial-1-c-and-cubeide-setup/advanced-c/enum.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
