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
35
#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;
    // Declare a variable called a_n1 of type int*.
    // Type int* means "address of an int".
    // Initialize a_n1 to &n1.
    // Expression &n1 means "address of n1".
    
    // printf("&n1 == %p\n", &n1);
    // // format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘int *’

    printf(" &n1 == %p\n", (void*)(&n1));
    printf("a_n1 == %p\n", (void*)(a_n1));

    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.