Learn C Programming

Lesson 5 of 9 · Structures, Unions and Enums

Module 12 · Structures, Unions and Enums

union and enum: When Each One Fits

Free with an accountReading

David's café menu from Module 5 has a fourth item now: 1 tea, 2 coffee, 3 juice, 4 cake. His switch runs from case 1: to case 4:, and further down one line adds ice when choice == 3.

Checking what this lesson needs for you…

What is inside union and enum: When Each One Fits

  1. enum: a name for every value in a set
  2. An enum variable accepts any int
  3. Printing the name of an enum value
  4. A switch on an enum, and the case you forgot
  5. Prefixes keep enum names apart
  6. union: one box, several labels
  7. Reading the member you did not write
  8. The tagged union: a tag says which member holds the value