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
36
37
38
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>

// sizeof(EXPRESSION) tells you the number of bytes needed to store an object/variable
// of the type of EXPRESSION.
//  - sizeof(1) tells you the number of bytes needed to store an int.
//    └ because 1 is an int.
//
//_____________________________________
// DO NOT USE THIS WAY OF USING SIZEOF
// sizeof(TYPE) tells you the number of bytes needed to store an object/variable of
// type TYPE.

int main(int argc, char* argv[]) {
    int  n   = 5;
    printf("sizeof(n) ==== %zd\n", sizeof(n));
    printf("sizeof(int) == %zd  ... BUT DO NOT USE THIS FORM\n", sizeof(int));
    printf("\n");

    int* a_n = &n; // &n means "address of n"
    printf("sizeof(a_n) === %zd\n", sizeof(a_n));
    printf("sizeof(int*) == %zd  ... BUT DO NOT USE THIS FORM\n", sizeof(int*));
    printf("\n");

    char ch  = 'A';
    printf("sizeof(ch) ==== %zd\n", sizeof(ch));
    printf("sizeof(char) == %zd  ... BUT DO NOT USE THIS FORM\n", sizeof(char));
    printf("\n");

    char* s  = "XYZ";
    printf("sizeof(s) ====== %zd\n", sizeof(s));
    printf("sizeof(char*) == %zd  ... BUT DO NOT USE THIS FORM\n", sizeof(char*));

    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.