Recall & Review
beginner
What is a structure in C?
A structure is a user-defined data type in C that groups different variables under one name. Each member has its own memory location.
Click to reveal answer
beginner
What is a union in C?
A union is a user-defined data type where all members share the same memory location. Only one member can hold a value at a time.
Click to reveal answer
intermediate
How does memory allocation differ between structures and unions?
Structures allocate separate memory for each member, so total size is sum of all members (plus possible padding). Unions allocate memory equal to the largest member only.
Click to reveal answer
intermediate
Can you access multiple members of a union at the same time?
No, because all members share the same memory, changing one member overwrites others. Only one member's value is valid at a time.
Click to reveal answer
beginner
When should you use a structure vs a union?
Use a structure when you need to store multiple values simultaneously. Use a union to save memory when only one value is needed at a time.
Click to reveal answer
Which of the following is true about structures in C?
✗ Incorrect
Structures allocate separate memory for each member, allowing multiple members to hold values simultaneously.
What is the size of a union in C?
✗ Incorrect
A union's size equals the size of its largest member because all members share the same memory.
If you assign a value to one member of a union, what happens to other members?
✗ Incorrect
Since all members share memory, assigning one member overwrites the others' data.
Which is a good reason to use a union instead of a structure?
✗ Incorrect
Unions save memory by sharing space among members, useful when only one member is used at a time.
Can a structure contain a union as a member in C?
✗ Incorrect
Structures can contain unions as members, allowing flexible data grouping.
Explain the main differences between a structure and a union in C.
Think about how memory is used and when you want to store multiple values or just one.
You got /4 concepts.
Describe a scenario where using a union is better than a structure.
Imagine you have a variable that can be an int or a float but never both at once.
You got /3 concepts.