Question: 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
Get step-by-step solutions from verified subject matter experts
