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>
#include <stdbool.h>
#include <assert.h>

int main(int argc, char* argv[]) {
    /* 'F' is at a_s_0     &(s[0])
     * 'l' is at a_s_0 + 1
     * 'u' is at a_s_0 + 2
     * 'f' is at a_s_0 + 3
     * 'f' is at a_s_0 + 4
     * '\0' is at a_s_0 + 5
     */
    char s[] = "Fluff";  // 6 elements in array because "…" implies the '\0' at the end.
    printf("s[0] == '%c'\n", s[0]);

    char a_s_0 = &( s[0] );
    printf("a_s_0 == &(s[0]) == %p\n\n", (void*)a_s_0);

    char* a_s_1 = &( s[1] );
    printf("a_s_1 == &(s[1]) == %p\n\n", (void*)a_s_1);

    printf("(a_s_0 + 1) ======= %p\n\n", (void*)(a_s_0 + 1));
    printf("(a_s_0 + 2) ======= %p\n\n", (void*)(a_s_0 + 2));

    char s_2 = *(a_s_0 + 2);  // a_s_0 is the address of the first character &(s[0])
                              // a_s_0 + 2 is the address of the third character &(s[2])
                              // *(a_s_0 + 2) is the value at that address, which is 'u';
    printf("s_2 == '%c'\n", s_2);
    
    return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */

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