1. 数组作为函数参数
注意传参时传的是数组+元素个数。
#include <stdio.h>
int SumArray(int array[], int n){
int sum = 0;
for (int i = 0; i < n; ++i) {
sum += array[i];
}
return sum;
}
int main(){
int arrays[] = {1,2,3,4,5};
int array_size[] = {1,2,3,4,5,6,7};
int a = SumArray(arrays, 5); // 15
int b = SumArray(array_size, 7); // 28
printf("%d\n", a);
printf("%d", b);
return 0;
}