1 - The predefined types
C is a typed language. This means in particular that any variable, constant or function is of a specific type. The type of an object defines how it is represented in memory.
The computer's memory is composed of a continuous sequence of bytes. Each byte of the memory ischaracterized by its address, which is an integer. Two contiguous bytes in memory have addresses that differ of a unit. When a variable is defined, it is assigned an address. This variable will correspond to a zone memory whose length (the number of bytes) is fixed by the type.
The memory size corresponding to the different types depends on the compilers; however, the ANSI standard specifies a number of constraints.
The basic types in C are characters, integers and floats (real numbers). They are designated by
the following keywords:
- char
- int
- float
- double
- short
- long
- unsigned
The character type char
#include < stdio.h>
int main() {
char c = 'E';
printf("%c", c + 1);
return 0;
}
Integers types
The keyword for the integer type is int. An object of type int is represented by a "natural" word of the machine used, 32 bits for a DEC alpha or an Intel PC.
The int type may be preceded by a precision attribute (short or long) and / or a representation attribute (unsigned). An object of type short int has at least the size of a float and at most the size of an int. In general, a short int is coded on 16 bits. An object of type long int has at least the size of an int (64 bits on a DEC alpha, 32 bits on an Intel PC).
Floating types
The float, double, and long double types are used to represent floating point numbers. They correspond to the different precisions possible.