Question: Problem 2 : Struct and Union Memory Layout Consider the following C declarations. Assume the following data type sizes: char: 1 byte short: 2 bytes

Problem 2: Struct and Union Memory Layout
Consider the following C declarations. Assume the following data type sizes:
char: 1 byte
short: 2 bytes
int: 4 bytes
double: 8 bytes
Assume the compiler:
Does not reorder fields.
Aligns each data type to its natural alignment (size of the data type).
Structures are aligned to the largest alignment requirement of their members.Tasks:
Memory Size Calculation
a) Calculate the size in bytes of union Info.
b) Calculate the size in bytes of struct Record.
Offset Calculation
Determine the offsets (in bytes) of:
a) data.value
b) status
3. Memory Optimization
Reorder the members of struct Record to minimize memory usage. Calculate the new size of struct Record after reordering.
Problem 2 : Struct and Union Memory Layout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!