CPSC 211, Sec 201-203: Quiz 5
Feb 18, 2004

Name:________________________________________

  1. (2 pts) Consider the C program below and draw the memory diagram (heap and stack) at point A.
    void init(int *p, int n) {
        int i;
        for (i = 0; i < n; i++)
            p[i] = i;
        /* point A */
    }
    
    int main () {
        int i;
        int a[5];
        init(a,5);
    }
    













  2. (3 pts) Consider the C program below and draw the memory diagram (heap and stack) at point A.
    int * init(int n) {
        int *p;
        int i;
        p = (int *) malloc(n*sizeof(int));
        for (i = 0; i < n; i++)
            p[i] = i;
        /* point A */
        return p;
    }
    
    int main () {
        int i;
        int *a;
        a = init(5);
    }