1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <stdlib.h>

struct Dog {
    char* name;
    int age;
};

int main(int argc, const char *argv[]) {
    struct Dog fido = {
        .name = "Fido",
        .age  = 1
    };

    // Assume ecegrid platform, Linux 64-bit

    // 1)  sizeof(fido) is __________.            ≥ 12
    // 2)  sizeof(fido.name) is ______.           = 8
    // 3)  whatis fido.name displays ________.    char*
    // 4)  sizeof(fido.name[0]) is ________.      1
    // 5)  whatis fido.name[0] displays ______.   char
    // 6)  whatis *fido.name displays ________.   char
    return 0;
}

/*  NULL
 *  - value is 0, but always write NULL in your code
 *  - required #include <stdlib.h>
 *  - We use it because we know the operating system will not
 *    let us access memory address 0, so if we try, we get
 *    a segmentation fault (which is good, in that case).
 *    That is telling you that you are writing outside
 *    the allowed "segment" of memory.
 */

This content is protected and may not be shared, uploaded, or distributed.    © 2019 Alexander J. Quinn.