logo

UTK Notes


Clicker Questions - 11-Pointers

Here is the state of addresses 0x7fa586401790 through 0x7fa58640182f. Our machine is little endian with 8-byte pointers.

Table.jpg

Here is a procedure, pm():

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void pm(unsigned long *p) {
    unsigned long **q;
    unsigned long ***r;
    unsigned long ****s;

    q = (unsigned long **) p;
    r = (unsigned long ***) p;
    s = (unsigned long ****) p;

    printf("0x%021x\n", (*p) & 0xff);       /* Line 1 of output. */
    printf("0x%021x\n", (**q) & 0xff);      /* Line 2 of output. */
    printf("0x%021x\n", (***r) & 0xff);     /* Line 3 of output. */
    printf("0x%021x\n", (****s) & 0xff);    /* Line 4 of output. */

    printf("0x%021x\n", (p[1]) & 0xff);     /* Line 5 of output. */
    printf("0x%021x\n", (q[1][1]) & 0xff);  /* Line 6 of output. */
}

Suppose pm() is called with p equal to 0x7fa586401790:

Question 1: What is the first line of ouput?

Answer p is 0x7fa586401790, so *p is the value at that address: 0x7fa5864017c8. The answer is 0xc8.

Question 2: What is the second line of ouput?

Answer *q is 0x7fa5864017c8, so **q is the value at that address: 0x7fa5864017c0. The answer is 0xc0.

Question 3: What is the third line of ouput?

Answer **r is 0x7fa5864017c0, so ***r is the value at that address: 0x7fa586401828. The answer is 0x28.

Question 4: What is the fourth line of ouput?

Answer ***s is 0x7fa586401828, so ****s is the value at that address: 0x7fa5864017f8. The answer is 0xf8.

Question 5: What is the fifth line of ouput?

Answer p+1 is 0x7fa586401798, so p[1] is the value at that: 0x7fa5864017d8. The answer is 0xd8.

Question 6: What is the sixth line of ouput?

Answer q[1] is 0x7fa5864017d8, so q[1][1] is the value at that: 0x7fa5864017e0: 0x7fa58664017a8 The answer is 0xa8.

PDF Download, 2022 Class Stats, 2023 Class Stats, 2024 Class Stats