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.
Sign in to read
This lesson is free, with an account
An account costs nothing and opens every lesson in this track that is not marked Pro, on every device you read on.
What is inside union and enum: When Each One Fits
- enum: a name for every value in a set
- An enum variable accepts any int
- Printing the name of an enum value
- A switch on an enum, and the case you forgot
- Prefixes keep enum names apart
- union: one box, several labels
- Reading the member you did not write
- The tagged union: a tag says which member holds the value