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 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include "clog.h"
int main(int argc, char* argv[]) {
int n = 5;
printf("sizeof(n) == %zd\n", sizeof(n));
printf("sizeof(int) == %zd … but do not use sizeof(TYPE)\n", sizeof(int));
int* a_n = &n;
printf("sizeof(a_n) == %zd\n", sizeof(a_n));
printf("sizeof(int*) == %zd … but do not use sizeof(TYPE)\n", sizeof(int*));
char ch = 'A';
printf("sizeof(ch) == %zd\n", sizeof(ch));
printf("sizeof(char) == %zd … but do not use sizeof(TYPE)\n", sizeof(char));
char* s = "XYZ";
printf("sizeof(s) == %zd\n", sizeof(s));
printf("sizeof(char*) == %zd … but do not use sizeof(TYPE)\n", sizeof(char*));
// sizeof is an operator (not a function or macro)
// sizeof takes either an expression or a type and returns the number of bytes
// needed to store an object of that type.
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.