Structs Preparation
Overview
C doesn’t have classes, but it does have struct
s! 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
struct
s 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:
- DIS 1.6 Struct Syntax
- DIS 2.7 Structs in Memory - Again, don’t worry about
malloc
and dynamic memory just yet (soon!)
Checks
Submit you answer to the following on Moodle.
-
What is the
struct
definition that will result in the following memory diagram?