Question: Matt wanted to flex his C programming skills by playing with structs and unions. He devised the following code: A. What is the output of

Matt wanted to flex his C programming skills by playing with structs and unions. He devised the following code:

Matt wanted to flex his C programming skills by playing with structs

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.

and unions. He devised the following code: A. What is the output

5 typedef union foo short long long int y char z; 7 10 foo t 12 typedef struct bar 13 E foo t foo stuffs [3]: char msg [64]; 16 ) bar t 18 void do_somethingl (bar_t a_bar) 19 E 20 21 strcpy (a bar msg, "do somethingl did something!") 23 bar 24 25 26 27 28 29 30 void main (int argc, char argvi) 31 32 t do something2 (void) bar t bar strcpy (bar msg, "do_something2 did something!"); return &bar bar t fun (bar t *) malloc (1 * sizeof (bar t)); strcpy (fun-msg, "If only something would happen. ..") ; 34 35 36 37 38 39 // do somethingl do_somethingl (fun) printf( "do something! result: %s ", fun->msg); // do something2 fun do something2 ) printf( "do something2 result: %s ", fun->msg)

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 Databases Questions!