Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions

Question

40 Job pricing and pay structures.

Answered: 1 week ago

Question

3.What are the Importance / Role of Bank in Business?

Answered: 1 week ago

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago