CS 211 - 2/8/13 Chapter 5 in K&R book Dynamic arrays Static Array double arr[30]; Dynamic Array Step 1: declare the variable as a pointer double *arr1; Warning - the following is an error word has no memory assigned to it char *word; strcpy (word, "hello"); Step 2: allocate the memory arr1 = ( double * ) malloc ( sizeof(double) * 20 ); arr1size = 20; Step 3: Store values arr1 [3] = 5.47; for (i = 0 ; i < arr1size ; ++i) arr1[i] = 0.0; *(arr1+5) = 7.2; arr1[5] = 7.2; Step 4: grow the array if (i >= arr1size) { double *temp = (double *) malloc (sizeof(double) * arr1size *2 ); for (i = 0 ; i < arr1size ; ++i) temp[i] = arr1[i]; free (arr1); arr1size *= 2; arr1 = temp; } arr1[i] = vl;