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 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
int main(int argc, char* argv[]) {
int a = 10;
int b = 0xa; // C integer constant written in hexadecimal (base 16) notation.
int c = 012; // C integer constant written in octal (base 8) notation.
int d = '\n'; // '\n' is a C character constant with value 10.
// GCC (or any other C compiler) does not care if you write it as
// '\n' (with single quotes) or as 10 (no quotes of any kind).
//
// WE do care. Use a character constant if you are referring to a
// character or a character's value. Use an integer constant 10 only
// if you are referring to a number of something (i.e., 10 of something).
int e = 10 + 0xa + 012 + '\n';
int e = e + e + e;
printf("e == %d\n", e);
printf("e == 0x%x\n", e);
printf("e == 0%o\n", e);
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2023 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.