Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider following program. Note that execution begins at “main”. (Don’t worry a

ID: 3750015 • Letter: C

Question

Consider following program. Note that execution begins at “main”. (Don’t 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 int’s

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

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

Explanation / Answer

a and e are global, static and uninitialized.

c is global, static and initialized.

f is a local, non-static and initialized.

g is local, non-static and un-initialized.

b is local, non-static and initialized.

d is local, non-static and uninitialized.

But do remeber that global and local is sometimes language specific and not common to all languages.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote