<分区>
Possible Duplicate:
when do we need to pass the size of array as a parameter
所以我刚开始使用数组,我需要创建 3 个函数来让我学习。
int sumarray(int a[], int n);
// a is an array of n elements
// sumarray must return the sum of the elements
// you may assume the result is in the range
// [-2^-31, 2^31-1]
int maxarraypos(int a[], int n);
// a is an array of n elements
// maxarraypos must return the position of
// the first occurrence of the maximum
// value in a
// if there is no such value, must return 0
bool lexlt(int a[], int n, int b[], int m);
// lexicographic "less than" between an array
// a of length n and an array b of length m
// returns true if a comes before b in
// lexicographic order; false otherwise
我将如何创建这些函数?
对于 sumarray
,我很困惑,因为数组存储的内容在一定长度内。为什么需要第二个参数 n
?
还有我如何测试一个使用数组的函数?我在想 sumarray([3], 3)
..对吗?