Sketch the data areas of functions main and silly as they ap

Sketch the data areas of functions main and silly as they appear immediately before the return from the first call to silly in excercise. x is 20, y is 22.

This problem is on page 364 from the book Problem Solving and Program Design in C edition 7th. You have to go back to page 362 from a quick excercise to do the problem.

If anyone could help me out is due wednesday i just need the answer for it. Thanks

Solution

int main(void)
{
int x, y;           //x(23456) = garbage, y(23460) = garbage. Assume the one in the braces is the address of the variable.
x = 10; y = 11;   //x(23456) = 10, y(23460) = 11.
silly(&x);          
silly(&y); /* values here */
. . .
}
void
silly(int *x)       //x(23454) = 23456
{
int y;               //y(23458) = garbage.
y = *x + 2;       //y(23456) = 10 + 2 = 12.
*x = 2 * *x;       //*x(23456) = 2 * 10 = 20. (***)
}
You want to find the status of the data variables as they appear immediately before the return
from the first call to silly(). That is, when you call silly(&x).
(***) At this point, the 2 variables in main() hold the values, x = 20, and y = 11.
   And the only two variables in silly() hold the values, x = 23456, and y = 12.

If you still have any further queries with this, just get back to me.

Sketch the data areas of functions main and silly as they appear immediately before the return from the first call to silly in excercise. x is 20, y is 22. This

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site