64,646
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
int big(int x,const int* y)
{
return x>=*y?x:*y;
}
int main()
{
int x,*y;
// 为y分配内存空间,你的y是一个野指针,当然在运行时要崩溃了!
y = new int;
cout < <"please enter x:" < <endl;
cin>>x;
cout < <"please enter *y:" < <endl;
cin>>*y;
// 条用函数的时候不要加* ,否则要错误,
//因为y才是一个指针,而第二个参数就是要一个指针;
cout < <"the bigger of x and *y is:" < <big(x,y) < <endl;
return 0;
}
#include <iostream>
using namespace std;
int big(int x, const int * y)
{
return x>=*y?x:*y;
}
int main()
{
int x,*y;
cout <<"please enter x:" <<endl;
cin>>x;
cout <<"please enter *y:" <<endl;
cin>>*y;
cout <<"the bigger of x and *y is:" <<big(x,y) <<endl;
fflush(stdin);
getchar();
return 0;
}