Skip to content
KnowledgeCity

Programming with C: Structs, Unions, and Constants

Understand the functions of the common C data structures structs, unions, and constants
Preview the first lesson free — get full access to all 5 lessons.
Course: On-Demand
Intermediate Provider Mike McMillan  5 Lessons ·  20m  in Arabic, German, English, Spanish, French, Portuguese, Chinese 

Course Description

Unlike many more modern programming languages, C does not have a wide variety of libraries for supplying advanced data structures. In these lessons, we’ll go over two other data structures you can use in C, the struct and the union.

We’ll go over how to define structs—special data structures that allow a programmer to create composite data types—how to create struct objects, how to add data to them, and how to use them in programs. You’ll also learn about unions, which allow one variable to hold more than one data type as a value. We’ll demonstrate how to create unions, how to assign data to them, how to access the data stored in a union, and what happens when you try to access a union's field when it’s not currently storing a value.

What You'll Learn

  • Define a new struct and create composite data types in C
  • Initialize struct objects and add data to them
  • Use structs to solve computing problems, including passing structs as function arguments
  • Create unions and assign data to them so one variable can hold more than one data type
  • Access data stored in a union, including what happens when accessing a field that is not currently storing a value
  • Create and use constants in C

Key Takeaways

  • Unlike many more modern programming languages, C does not have a wide variety of libraries for supplying advanced data structures.
  • A struct is a special data structure that allows a programmer to create composite data types.
  • A union allows one variable to hold more than one data type as a value.
  • The course covers what happens when you try to access a union's field when it is not currently storing a value.
  • Structs can be passed as function arguments within C programs.

Frequently Asked Questions

What does this C programming course cover?

It covers two data structures you can use in C: the struct and the union. You learn how to define structs, create struct objects, add data to them, use them in programs (including as function arguments), and how to create unions, assign data to them, and access the data stored in a union. It also covers creating and using constants.

What is the difference between a struct and a union as taught here?

A struct is a special data structure that lets a programmer create composite data types, while a union allows one variable to hold more than one data type as a value.

What skills does this course help build?

It builds skills in C (Programming Language), C Compilers, C Data Types, C-Based Programming Languages, Data Structures, and Modular Programming in C.

What lessons are included in this course?

The lessons are Creating Structs, Using Structs, Structs as Function Arguments, Creating and Using Unions, and Creating and Using Constants.

Why does C use structs and unions for data structures?

Unlike many more modern programming languages, C does not have a wide variety of libraries for supplying advanced data structures, so structs and unions are two data structures you can use in C.