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
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[]) {
    int n = 4 * 4;  // asterisk used for multiplication

    int* a_n = &n;  // declare a_n as an address of an int
    printf("a_n == %p\n", (void*) a_n);

    int z = *a_n;   // access the value *at* address a_n (and assign it to z)
    printf("z    == %d\n", z);
    printf("*a_n == %d\n", *a_n);

    *a_n = 555;
    printf("__________________________________________\n");
    printf("*a_n =  555;\n");  // Write 555 at the address stored in a_n
    printf("*a_n == %d\n", *a_n);
    printf("z    == %d\n", z);

    char s[3] = "Yo";  // array on the stack;  actually char s[] = "Yo";
    char* t   = "Mi";  // address of an array (string) elsewhere (data segment)

    printf("__________________________________________\n");
    printf("s[0] == %c\n", s[0]);  // print first character in the array s
    printf("t[0] == %c\n", t[0]);  // print first character in the array at t
    
    return EXIT_SUCCESS;
}

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