#include <stdio.h>
void getsum(int pt[],int size );
void getsum1(int * head,int * tail );
int main()
{
int i_arr[5] = { 1, 20, 3, 4, 5 };
int *pt;
getsum(i_arr,5);
getsum1(i_arr,&i_arr[4]);
printf("获取指定位置的元素值:索引方式-%d ,指针方式-%d\n", i_arr[4] ,*(i_arr + 4 ) );
printf("one-%d two-%d\n", *i_arr+1, 0 );
printf("%zd\n", &i_arr[2] - i_arr );
return 0;
}
//参数为:数组头指针、数组长度
void getsum(int pt[],int size )
{
int sum = 0;
for (int i = 0; i < size; ++i)
{
sum = sum + *(pt);
pt++;
}
printf("%d\n", sum);
return ;
}
//参数为:数组头指针、数组尾指针
void getsum1(int * head,int * tail )
{
int sum = 0;
while( head <= tail )
{
sum = sum + *head;
head++;
}
printf("%d\n", sum);
return;
}