Answered step by step
Verified Expert Solution
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
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
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