COMP9024 (19T0) COMP9024 (19T0) Sample Midterm Exam Data Structures and Algorithms
[Instructions] [C language]
[Q1] [Q2] [q3] [Q4] [Q5]

Question 3 (4 marks)

  1. Given the following definition:
    int data[12] = {5, 3, 6, 2, 7, 4, 9, 1, 8};
    
    and assuming that &data[0] == 0x10000, what are the values of the following expressions?

    data + 4
    *data + 4
    *(data + 4)
    data[4]
    *(data + *(data + 3))
    data[data[2]]

  2. Consider the following piece of code:
    typedef struct {
       int   studentID;
       int   age;
       char  gender;
       float WAM;
    } PersonT;
    
    PersonT per1;
    PersonT per2;
    PersonT *ptr;
    
    ptr = &per1;
    per1.studentID = 3141592;
    ptr->gender = 'M';
    ptr = &per2;
    ptr->studentID = 2718281;
    ptr->gender = 'F';
    per1.age = 25;
    per2.age = 24;
    ptr = &per1;
    per2.WAM = 86.0;
    ptr->WAM = 72.625;
    

    What are the values of the fields in the per1 and per2 record after execution of the above statements?

    Hint:  ptr->t  means the same as  (*ptr).t

Type your answers to the above questions into the file called q3.txt (provided) and submit it using the command:

$ submit q3

The above command will make a copy of q3.txt as your answer for this question.