Page 131 - C-Language
P. 131
Chapter 17: Data Types
Remarks
• While char is required to be 1 byte, 1 byte is not required to be 8 bits (often also called an
octet), even though most of modern computer platforms define it as 8 bits. The
implementation's number of bits per char is provided by the CHAR_BIT macro, defined in
<limits.h>. POSIX does require 1 byte to be 8 bits.
• Fixed width integer types should be use sparsely, C's built-in types are designed to be
natural on every architecture, the fixed width types should only be used if you explicitly need
a specifically sized integer (for example for networking).
Examples
Integer types and constants
Signed integers can be of these types (the int after short, or long is optional):
signed char c = 127; /* required to be 1 byte, see remarks for further information. */
signed short int si = 32767; /* required to be at least 16 bits. */
signed int i = 32767; /* required to be at least 16 bits */
signed long int li = 2147483647; /* required to be at least 32 bits. */
C99
signed long long int li = 2147483647; /* required to be at least 64 bits */
Each of these signed integer types has an unsigned version.
unsigned int i = 65535;
unsigned short = 2767;
unsigned char = 255;
For all types but char the signed version is assumed if the signed or unsigned part is omitted. The
type char constitutes a third character type, different from signed char and unsigned char and the
signedness (or not) depends on the platform.
Different types of integer constants (called literals in C jargon) can be written in different bases,
and different width, based on their prefix or suffix.
/* the following variables are initialized to the same value: */
int d = 42; /* decimal constant (base10) */
int o = 052; /* octal constant (base8) */
int x = 0xaf; /* hexadecimal constants (base16) */
int X = 0XAf; /* (letters 'a' through 'f' (case insensitive) represent 10 through 15) */
Decimal constants are always signed. Hexadecimal constants start with 0x or 0X and octal
https://riptutorial.com/ 107

