指针作函数参数

来源:百度知道 编辑:UC知道 时间:2024/05/13 05:56:46
我想用C++编一个用指针作函数参数的MAX()函数,比较一个数组里的数值并选出最大值。
请问怎么编呢?

#include<iostream.h>
int max(int *s);
main()
{
int a[N]={……};
int i,p;
for(i=0;i<=N-1;i++)
p=max(&a[i]);
cout<<"最大数为“<<p<<endl;
}
int max(int *s)
{
max=0;
if(*s>max) max=*s;
return max;
}

这样就可以了吧