From the course: C Programming: Exploring Advanced Concepts and Practical Applications

Unlock the full course today

Join today to access over 23,400 courses taught by industry experts.

Creating enumerated constants

Creating enumerated constants

- [Instructor] The mysterious enum keyword may be neglected, but it's certainly useful. In C, it's used to create enumerated constants or a series of constants numbered sequentially, though they don't necessarily need to be sequential. The enum keyword is followed by a set of braces. Between the braces are constants separated by commas. The constants are assigned values, sequentially, starting with zero. In this example, alpha is zero, beta is one, gamma is two, and delta is three. The values can be altered by assignments. Here, the first values is one, then two, then three. With this example, the first value is zero, the next is five, and then six, seven, and eight. This code shows the enum keyword, as I often use it to define true and false constants. The identifiers can be upper or lower case. The I prefer upper for this type of constant. The program outputs the values to confirm their assignments. False is zero, true is one. Remember that the first item is zero unless you specify…

Contents