Question: #include #include // PROBLEM 1 int a[4]; int *b[4]; int *q; int **r; int ***s; int * f(int a) { int x[4]; return &x[a]; }

#include  #include  // PROBLEM 1 int a[4]; int *b[4]; int *q; int **r; int ***s; int * f(int a) { int x[4]; return &x[a]; } int main() { printf("a[0] %d ", a[0]); printf("a[1] %d ", a[1]); printf("a[2] %d ", a[2]); printf("a[3] %d ", a[3]); printf("q %p ", q); printf("r %p ", r); printf("s %p ", s); printf("&a[0] %p ", &a[0]); printf("&a[1] %p ", &a[1]); printf("&a[2] %p ", &a[2]); printf("&a[3] %p ", &a[3]); printf("&q %p ", &q); printf("&r %p ", &r); printf("&s %p ", &s); // Q1. Draw the box-circle diagram for a, q, r, and s // Q2. Based on the output, how many bytes is a int. Explain // Q3. Based on the output, how many bytes is a pointer. Explain // Q4. What are the initial values of the variables? Explain q = (int *) malloc(sizeof(int)); r = &q; s = &r; // Q5. Draw the box-circle diagram for a, q, r, and s for (int i = 0; i < 4; i++) { b[i] = (int *) malloc(sizeof(int)); (*b)[i] = i; } for (int i = 0; i < 4; i++) { b[i] = &a[i%2]; } // Q6. What locations are garbage at this point? // What are the dangling references at this point? b[2] = f(2); // Q7. What locations are garbage at this point? // What are the dangling references at this point? struct T { int a; struct T* next; } y, *z; y.next = (struct T *) malloc(sizeof(struct T)); z = &y; y.next = z; b[2] = &((*z).a); // Q8. Draw the box-circle diagram for y, z, and b at this point // Q9. What locations are garbage at this point? 

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!