#include #include void desallocation(void* ptr) { if (ptr != NULL) { printf("Desallocation a l'adresse : %p\n", ptr); free(ptr); } else { printf("Attention, tentative de desallocation de NULL"); } } void main(void) { size_t taille1 = 5; printf("Allocation de %zu octets ", taille1 * sizeof(double)); printf("pour un tableau de %zu double\n", taille1); double* ptr1 = (double*) malloc(taille1 * sizeof(double)); if (ptr1 == NULL) { printf("Allocation avortee\n"); } else { printf("Allocation reussie a l'adresse : %p\n", ptr1); } size_t taille2 = 80 * (1024ULL * 1024ULL * 1024ULL); double* ptr2 = (double*) malloc(taille2); printf("Tentative d'allocation de %zu octets ", taille2); printf("soit %zu Go\n", taille2 >> 30); if (ptr2 == NULL) { printf("Allocation avortee\n"); } else { printf("Allocation reussie a l'adresse : %p\n", ptr2); } printf("\n"); desallocation(ptr1); ptr1 = NULL; desallocation(ptr2); ptr2 = NULL; }