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
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