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
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