1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#define TOREALLOC 10
int
main (void)
{
double **mat = calloc(20, sizeof(double*));
unsigned i;
for (i = 0; i < 20; i++){
mat[i] = calloc(3, sizeof(double));
assert(mat[i] != NULL);
}
printf("\nBefore: %p \n", mat);
mat = realloc(mat, TOREALLOC * sizeof(double*));
assert(mat != NULL);
printf("\nafter: %p - sizeof double: %d \n", mat, sizeof(double));
for (i = 10; i < 20; i++){
printf("\nValue: %d - %p \n", i, mat[i]);
fflush(stdout);
free(mat[i]);
}
return 0;
} |