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

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

    int n1 = 5;
    printf("n1 == %d\n", n1);

    int* a_n1 = &n1;
    int n2 = *a_n1;  // n2 gets *a_n1
                     // *a_n1 means "value at a_n1"

    printf("n2 == %d\n", n2);

    *a_n1 = 7;  // Store 7 at (the address) a_n1.
    printf("n1 == %d\n", n1);

    printf("n2 == %d\n", n2);

    return EXIT_SUCCESS;
}
/*
n.c: In function ‘main’:
n.c:17:18: warning: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘int *’ [-Wformat=]
  printf("&n1 == %p\n", &n1);
                 ~^     ~~~
                 %ls
n1 == 5
&n1 == 0x7ffc1ba9d614
*/

/* 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.