在堆中分配一个数组之后。我正在尝试创建一个函数 max 来查找带有指针的数组中的最大数字,但它给了我这个错误:-In function 'int main()': error:max,cannot用作函数。这是代码:
#include<iostream>
using namespace std;
int max(int *v,int n){
int i,max=0;
for(i=1;i<=n;i++){
if(*(v+i)>max)
max=v[i];
}
return max;
}
int main(){
int *v,n,i;
//read n
cout<<"Number of elements ";
cin>>n;
v = new int[n];
//read elements
cout<<"Array Ellements:";
for(i=1;i<=n;i++){
cin>>v[i];
}
// output array elements
for(i=1;i<=n;i++){
cout<<v[i];
if(i<n)
cout<<",";
}
cout<<endl;
//max store the biggest number in the array
int max;
max = max(v,n);
return 0;
}