Given the following array and pointer declarations, show two different code fragments to calculate and display the sum of the elements of the array x. One approach is to subscript the array in a loop over the elements of the array. The other approach is to use a combination of advancing the pointer ptr thru the array and dereferencing it.
file: 1c.c (get the C source here),
#define SIZE_D(array) (sizeof(array) / sizeof(array[0]))
//…
[code]
double x[] = {3.14, 2.7, 2.1, 1.41, 100.1};
const int X_CAP = SIZE_D( x );
double *ptr = x;
[/code]