1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main(int argc, char* argv[]) {
    
    // These are *almost* the same, except that the int takes more space in memory
    char a1 = 'A'; // one byte
    int  a2 =  65; // sizeof(a2) bytes  (same as sizeof(int))

    // These are *almost* the same.  The size of each in memory is different.  Use
    // the one that matches what you *mean*.
    bool b1 = true; // use bool if you are referring to a boolean value (e.g., a condition)
    int  b2 = 1;    // use int  if you are referring to a number of things
    char b3 = 1;    // use char if you are referring to a character (e.g., 'A')

    printf("sizeof(b1) == %d\n", sizeof(b1));
    printf("sizeof(b2) == %d\n", sizeof(b2));
    printf("sizeof(b3) == %d\n", sizeof(b3));

    return EXIT_SUCCESS;
}

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