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
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[]) {

    int array[] = { 264, 20875, 362, 270 };
    for(int i = 0; i < 4; i++) {
        printf("array[i] == %d\n", array[i]);
    }

    int* a_n = &array[0];

    printf("\n");
    printf("*a_n     == %d\n", *a_n);
    printf(" a_n      == %p\n", (void*)a_n);
    printf("array[0] == %d\n", array[0]);

    printf("\n");
    printf("*(a_n + 1) == %d\n", *(a_n + 1));
    printf(" (a_n + 1) == %p\n", (void*)(a_n + 1));
    printf("array[1] == %d\n", array[1]);
    
    printf("\n");
    printf("*(a_n + 2) == %d\n", *(a_n + 2));
    printf(" (a_n + 2) == %p\n", (void*)(a_n + 2));
    printf("array[2] == %d\n", array[2]);
    
    // LESSON:  When you add to an address, you add in increments of
    // the size of the type that it refers to.

    return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

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