1 int main(int argc, char *argv[])
2 {
3 int i;
4
5 double* p; // We uses this reference variable to access
6 // dynamically created array elements
7
8 p = calloc(10, sizeof(double) ); // Make double array of 10 elements
9
10 for ( i = 0; i < 10; i++ )
11 *(p + i) = i; // put value i in array element i
12
13 for ( i = 0; i < 10; i++ )
14 printf("*(p + %d) = %lf\n", i, *(p+i) );
15
16
17 free(p); // Un-reserve the first array
18
19 putchar('\n');
20
21 p = calloc(4, sizeof(double) ); // Make a NEW double array of 4 elements
22
23 // ***** Notice that the array size has CHANGED !!! ****
24
25 for ( i = 0; i < 4; i++ )
26 *(p + i) = i*i; // put value i*i in array element i
27
28 for ( i = 0; i < 4; i++ )
29 printf("*(p + %d) = %lf\n", i, *(p+i) );
30
31 free(p); // Un-reserve the second array
32 }
33