Question
May 2, 2009 at 01:01 PM
seanlee1989

Need some assistance..

by seanlee1989 . Updated 17 years, 4 months ago

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]

This discussion is locked

All Comments