> For the complete documentation index, see [llms.txt](https://hkust-robotics-team.gitbook.io/hkust-robotics-team-software-tutorial/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hkust-robotics-team.gitbook.io/hkust-robotics-team-software-tutorial/tutorial/tutorial-1-c-and-cubeide-setup/advanced-c/enum.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` 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>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
