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:

  1. char 
  2. int 
  3. float 
  4. double 
  5. short 
  6. long 
  7. unsigned

The character type char

The keyword char designates an object of type character. A char can contain any element of the character set of the machine used. Most of the time, a char object is coded on a byte; it is the most elementary object in C. The character set used generally corresponds to ASCII coding (on 7 bits). The most machines now use the ISO-8859 (8-bit) character set, whose first 128 characters are ASCII characters. The last 128 characters (encoded on 8 bits) are used for characters specific to different languages.
One of the peculiarities of the char type in C is that it can be likened to an integer: any object of type char can be used in an expression that uses integer objects. For example, if c is of type char, the expression c + 1 is valid. It designates the next character in the ASCII code. Thus, the following program prints the character 'B'.

#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.

Recapitulations

Younes Derfoufi 

Leave a Reply