Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following C program: typedef struct { int x; int y; } Thing; Thing *makeThing(int a, int b); int main() { Thing *p; p

image text in transcribed

Consider the following C program: typedef struct { int x; int y; } Thing; Thing *makeThing(int a, int b); int main() { Thing *p; p = makeThing(5, 50); printf("p->x=%d, p->y=%d ", p->x, p->y); } Thing *makeThing(int a, int b){ Thing thing; thing.x = a; thing.y = b; return &thing; } The designer intended that the makeThing function would create a Thing structure whose x and y values equaled its input parameters a and b respectively, that it would return a pointer to the newly created structure so it could be accessed by other parts of the program, and that the program would print: p->x = 5, p->y = 50 However, there is a problem with the makeThing function. (assume all the code is correct, there is a logical error only). (a) Describe what the problem is? (b) Rewrite the body of the makeThing function to correct the problem. The function prototype should remain the same

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

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

Which statement best describes Kaizen Event?

Answered: 1 week ago