Les types fondamentaux

Types fondamentaux Archive du 22/11/2016 le 04/03/2020

Booléan

bool : false vaut 0, true vaut 1 mais une valeur différente de 0 est aussi acceptée.

Caractères

char : caractère sur un octet. Généralement signé sur ordinateur mais peut être non signé sur d'autres systèmes (certains microcontrôleurs, etc…).

wchar_t : caractère UTF-8.

char16_t : caractère UTF-16.

char32_t : caractère UTF-32.

Nombres entiers

Les nombres entiers peuvent être signé ou non signé. char par défaut pouvant être signé ou non signé, il est conseillé de toujours indiquer explicitement unsigned char ou signed char.

char : 1 octet.

short : 2 octets.

int : entre 2 octets (système 16 bits) et 4 octets.

long : entre 4 (Windows) et 8 (Linux) octets.

long long : 8 octets.

Nombres à virgules

float : 4 octets

double : 8 octets.

long double : 8 (32 bits) à 16 octets (64 bits).

Pointeurs

int main() {
  int a;
  int* b = &a;
  b = &a;
  *b = 1;
  const int* c = &a;
  c = &a;
  *c = 1;  // error: assignment of read-only location '* c'
  int const* d = &a;
  d = &a;
  *d = 1;  // error: assignment of read-only location '* d'
  int* const e = &a;
  e = &a;  // error: assignment of read-only variable 'e'
  *e = 1;
  int const* const f = &a;
  f = &a;  // error: assignment of read-only variable 'f'
  *f = 1;  // error: assignment of read-only location '*(const int*)f'
}