Quiz: Structure & Union
Quiz: Structure & Union checks how well you can apply Memory layout of struct and Union size equals largest member (and related ideas) in C.
Introduction
Quiz: Structure & Union checks how well you can apply Memory layout of struct and Union size equals largest member (and related ideas) in C. Try each prompt in a scratch file before moving on.
Understanding the topic
Challenge 1 In your own words — or with a tiny program — show that you understand: Memory layout of struct.
Challenge 2 In your own words — or with a tiny program — show that you understand: Union size equals largest member.
Challenge 3 In your own words — or with a tiny program — show that you understand: enum for named constants.
Challenge 4 In your own words — or with a tiny program — show that you understand: typedef with struct.
- Challenge 1 — In your own words — or with a tiny program — show that you understand: Memory layout of struct.
- Challenge 2 — In your own words — or with a tiny program — show that you understand: Union size equals largest member.
- Challenge 3 — In your own words — or with a tiny program — show that you understand: enum for named constants.
- Challenge 4 — In your own words — or with a tiny program — show that you understand: typedef with struct.
Step-by-step explanation
- Challenge 1 — In your own words — or with a tiny program — show that you understand: Memory layout of struct.
- Challenge 2 — In your own words — or with a tiny program — show that you understand: Union size equals largest member.
- Challenge 3 — In your own words — or with a tiny program — show that you understand: enum for named constants.
- Challenge 4 — In your own words — or with a tiny program — show that you understand: typedef with struct.
Execution workflow
Challenge 1
In your own words — or with a tiny program — show that you understand: Memory layout of struct.
Best practices
- Enable warnings: gcc -Wall -Wextra -std=c11 source.c -o app
- Give every variable a defined value before it is read.
- Stay inside array bounds — C will not stop you from over-running a buffer.
Common mistakes
- Reading uninitialized storage — behavior is undefined.
- Dismissing compiler warnings instead of fixing root causes.
- Ignoring NULL returns from malloc, fopen, and similar APIs.
Hands-on exercise
Practice problems:
- Build or explain: Memory layout of struct
- Build or explain: Union size equals largest member
- Build or explain: enum for named constants
- Build or explain: typedef with struct
Summary
Quiz: Structure & Union in C — Self-check on layout and enum usage.