Question: Draw memory contents (heap and stack) at the execution point indicated in foo. #include #include int *foo( int *a, int *b, int s); int main

Draw memory contents (heap and stack) at the execution point indicated in foo.

#include

#include

int *foo(int *a, int *b, int s);

int main () {

int *arr = NULL, x = 6, y = 7, i;

arr = foo(&x, &y, 5);

printf("x = %d y = %d ", x, y);

if(arr != NULL) {

for(i=0; i < 5; i++) {

printf("arr[%d] = %d ",

i, arr[i]);

}

}

free(arr);

return 0;

}

/************************************/

int *foo(int *a, int *b, int s) {

int *tmp, i;

tmp = malloc(sizeof(int)*s);

if(tmp != NULL) {

for(i=0; i < s; i++) {

tmp[i] = i + *b;

}

*a = tmp[2];

*b = 8;

}

// DRAW MEMORY WHEN YOU GET HERE

return tmp;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!