Question: Programming in C. I have two Questions. 1. Given the structure definitions typedef struct { int Counter; float Average; } hit_rate_type; typdef struct { char

Programming in C. I have two Questions. 1. 

Given the structure definitions

typedef struct { int Counter; float Average; } hit_rate_type; typdef struct { char *Name; hit_rate_type Killer; } murder_type; murder_type *JackTheRipper; 

write code that mallocs memory for JackTheRipper, stores the name "Jack the Ripper" in the Name field, and stores 99 in the Counter.

How do I solve this? Is this(below) a correct answer?

typedef struct { int Counter; float Average; } hit_rate_type;

typedef struct { char *Name; hit_rate_type Killer; } murder_type;

main(){

murder_type *JackTheRipper; hit_rate_type hitRate; hitRate.Counter = 99; JackTheRipper = malloc(sizeof(murder_type)); JackTheRipper->Killer = hitRate; JackTheRipper->Name = "JackTheRipper";

}

-----------------

Prob2.

Assuming that an int occupies 2 bytes, what is the output from the following code?

typedef union { int WholeThing; struct { unsigned Top:8; unsigned Middle:4; unsigned Bottom:4; } Parts; } int_parts_type; int_parts_type MyParts; MyParts.WholeThing = 0x1BB2; printf("%d ",MyParts.Parts.Middle); 

This prints 11. Could you please explain to me why???

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!