Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 2 (Structs and Unions) (20 points) Matt wanted to flex his C programming skills by playing with structs and unions. He devised the following
Problem 2 (Structs and Unions) (20 points) Matt wanted to flex his C programming skills by playing with structs and unions. He devised the following code 5 typedef union foo short x long long int y char z 10foo t 12 typedef struct bar 13 14 15 16 bart; 17 18 Vvoid do somethingl (bar t a bar) 19 E 20 21 foo t foo stuffs [3]: char msg [64]: strcpy (a bar msg, "do somethingl did something! ") 23 bar t do something2 (void) 24 E 25 26 27 28 bar t bar strcpy bar .msg, "do_something2 did something!"): return &bar 30 void main (int argc, char argv) 31 E 32 bar t fun(bar tmalloc (1 sizeof (bar t)); strcpy (fun-msg, "If only something would happen. ) 34 35 36 37 38 39 40 // do somethingl do_something1 (*fun) : printf("do-something! result: %s ", fun >msg); // do_something? fun do something2() ; printf("do-something2 result: %s ", fun->msg); 43 A. What is the output of the two print statements in lines 38 and 42? Explain this result. B. In Part A, if the expected result differed from the actual result, how might you change the existing code to work as intended? C. Show the partitioning of the bar_t struct (i.e., show the number of bytes dedicated to each field) D. How many bytes does the bar t struct require in total? E. Using the following assembly code compiled by GCC, draw the stack frame for do_something2. You must show each member field for any composite structures
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started