• Why use typedef?

    To convey the intended use of a variable

  • How to use typedef?

    Syntax:

    Example:

  • Why use enums?

    To convey that a variable can be one of serveral possible values

  • How to use an enum?

    Syntax:

    Example:

  • Using typedef with enum

    Example:

    enum_with_typedef.c:

      Note:
    • using typedef will reduce typing out enum each time, but will put your enum_type_name into the global namespace
  • Using enum with switch

    Example:

    enum_with_switch.c:

      Note:
    • the switch statement is far more expressive than using integers
    • the management of the numbering scheme (adding/removing/reordering of members) is handled by C