编写一个函数,该函数具有两个形参,分别为int型和指向Int型的指针,并返回这两个int值之中较大的数值.考虑应将其指针形参定义为什么类型?
#include <iostream>
using namespace std;
int max(const int &x,const int* &y)
{
return x>= *y ?x: *y;
}
void main( )
{
int v1=90;
int v2=20;
int* v3=&v2;
cout<<max(v1,v3);
}
//OR
#include <iostream>
using namespace std;
int max(const int &x,const int &y)
{
return x>= y ?x: y;
}
void main( )
{
int v1=90;
int v2=20;
int* v3=&v2;
cout<<max(v1,*v3);
}