Overview

C doesn’t have classes, but it does have structs! Today, we’ll be focusing on these pseudo-classes, how we can use them, and what they tell us about memory organization.

Basic Learning Objectives

Before class, you should be able to:

  • Define a struct in C
  • Explain how a struct differs from a traditional class
  • Explain how a struct differs from an array

Advanced Learning Objectives

After class, you should be able to:

  • Explain how structs are represented in memory
  • Demonstrate how complex elements (e.g. structs with nested arrays) of an array are stored in memory
  • Identify when padding will be necessary for a struct in memory

Resources

Read the following:

Checks

Submit you answer to the following on Moodle.

  1. What is the struct definition that will result in the following memory diagram?

    A diagram with boxes representing different sizes of memory

  • If you’d like more practice, check out DIS exercises for 1.6 and 2.7.