there is a sample in the chapter pointer of C Primer Plus Book.
I am so confuse about the code which set the array name into the sump function as formal parameter
Answer = sump(array, array + SIZE);
start is 00EFFBD8
,it is ok that means arrary[0]
address
but when it action:
int *end = array +SIZE // => "array[0] address + 10"
why end is 00EFFC00 (00EFFBD8 + 10*4)
, why not 00EFFBD8 +10
???
#include <stdio.h>
#array size
#define SIZE 10
#sum function
int sump(int *start, int *end);
int main(void)
{
int array[SIZE] = { 10,9,8,7,6,5,4,3,2,1 };
long Answer;
Answer = sump(array, array + SIZE);
printf("a is %d\n", Answer);
return 0;
}
int sump(int *start, int *end)
{
int total=0;
while (start < end)
{
printf("start is %p, %d\n", start, *start);
printf("end is %p, %d\n", end, *end);
total += *start++;
}
return total;
}