malloc (suite)

On peut allouer dynamiquement de la mémoire pour n'importe quel type de donnée. C'est le type du pointeur de cast qui changera le type (void*) du pointeur retourné par malloc.

un entier
int* pin;
pin = (int*) malloc(sizeof(int));

un réel
int* pr;
pr =
(float*) malloc(sizeof(float));

un caractère
char* pc;
pc = (char*) malloc(sizeof(char));

une chaîne de 20 caractères
char* ps;
ps = (char*) malloc(20*sizeof(char));
Une variable structurée point
typedef struct {
                     int px;
                     int py;
                      } point;
point* po;
po = (point*)  malloc(sizeof(point));

Un tableau de 40 points
point* tabPo;
tabPo = (point*)  malloc(40*sizeof(point));
suivant                plan