Question: Consider following program. Note that execution begins at main. (Dont worry about what the program actually does . You will be studying where the variables

Consider following program. Note that execution begins at main. (Dont worry about what the program actually does. You will be studying where the variables are allocated.)

int *a, *e;

int c=4;

void DoFunctionB(int in1, int* in2) {

int f=6;

f++; // Accesses the local variable

in2 = malloc(500 * sizeof(int*)); // Dynamically allocate some int*s

*in2 = in1;

}

int DoFunctionA(int in1, int* in2) {

int *g;

DoFunctionB(in1++,in2++); // Call DoFunctionB with the passed-in args

g = in2;

return(in1);

}

void main( void ) {

int b=0;

int *d;

d = malloc(100 * sizeof(int)); // Dynamically allocate some ints

e = malloc(100 * sizeof(int)); // Dynamically allocate some ints

b = DoFunctionA(c,a); // Pass some variables into DoFunctionA

// note use of a and c

}

Assume that an int and an int * are both 4 bytes (32 bits) in size. When DoFunctionB is running (and its call to malloc has been made), how much space is in use in RAM? Break down the usage by the statically allocated RAM area, the heap, and the stack.

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!