naxiaorongshixiatian
naxiaorongshixiatian
2015-10-24 13:58
采纳率: 100%
浏览 1.5k

指针型函数参数不能为非指针型的吗

#include

using namespace std;
int * min(int a,int b,int c){
int *p=0;

if(a<b)
p=&a;
else p=&b;
if(*p>c)
p=&c;
return p;

}

int main()
{
int a,b,c;
int *p=0;
cout<<"please input a,b,c:";
cin>>a>>b>>c;
p=min(a,b,c);
cout<<"最小值为:"<<*p<<endl;
cout<<"a="<<a<<endl;
cout<<"b="<<b<<endl;
cout<<"c="<<c<<endl;

return 0;

}图片

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • DouMiaoO_Oo
    DouMiaoO_Oo 2015-10-24 14:05
    已采纳

    能详细描述你的问题么

    点赞 评论
  • DouMiaoO_Oo
    DouMiaoO_Oo 2015-10-24 14:14
     #include <iostream>
    using namespace std;
    int *min(int a, int b, int c){
        int *p = 0;
        cout << "函数内的a地址: " << &a << endl;
        if(a < b)
            p = &a;
        else
            p = &b;
        if(*p > c)
            p = &c;
        return p;
    }
    
    int main()
    {
        int a, b, c;
        int *p = 0;
        cout<<"please input a,b,c:\n";
        cin >> a >> b >> c;
        cout << "输入的a的地址: " << &a << endl;
        p = min(a, b, c);
    
        cout<<"最小值为:"<<*p<<endl;
        cout << "p的地址是:" << p << endl;
        cout<< "a=" << a << endl;
        cout<< "b=" << b << endl;
        cout<< "c=" << c << endl;
        return 0;
    }
    
    

    图片说明

    点赞 评论

相关推荐