1
2// declare a pointer variable to point to allocated heap space
3int *p_array;
4double *d_array;
5
6// call malloc to allocate that appropriate number of bytes for the array
7
8p_array = (int *)malloc(sizeof(int)*50); // allocate 50 ints
9d_array = (int *)malloc(sizeof(double)*100); // allocate 100 doubles
10
11
12// use [] notation to access array buckets
13// (THIS IS THE PREFERED WAY TO DO IT)
14for(i=0; i < 50; i++) {
15 p_array[i] = 0;
16}
17
18// you can use pointer arithmetic (but in general don't)
19double *dptr = d_array; // the value of d_array is equivalent to &(d_array[0])
20for(i=0; i < 50; i++) {
21 *dptr = 0;
22 dptr++;
23}
24