Skip to content

Commit 2df1434

Browse files
committed
arrays are passed as pointers
1 parent c36b40a commit 2df1434

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

prog.11.12.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Function to sum the elements of an integer array Ver. 2
2+
3+
#include <stdio.h>
4+
5+
int arraySum (int *array, const int n)
6+
{
7+
int sum = 0;
8+
int * const arrayEnd = array + n;
9+
10+
for ( ; array < arrayEnd; ++array )
11+
sum += *array;
12+
13+
return sum;
14+
}
15+
16+
int main (void)
17+
{
18+
int arraySum (int *array, const int n);
19+
int values[10] = { 3, 7, -9, 3, 6, -1, 7, 9, 1, -5 };
20+
21+
printf ("The sum is %i\n", arraySum (values, 10));
22+
23+
return 0;
24+
}

0 commit comments

Comments
 (0)