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
}
For each variable (a-g) describe whether the variable itself is global or local, static or not static, and initialized or uninitialized. (Hints: Global variables are always static. Local variables become static when declared with static. For pointers, consider the pointer itself, not anything the pointer might point to.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
