标题:此程序为什么得不到期望值20和4435500??大神们,求分析????????? ...
取消只看楼主
芦苇太帅了
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2013-8-16
结帖率:75%
已结贴  问题点数:20 回复次数:1 
此程序为什么得不到期望值20和4435500??大神们,求分析?????????
#include<iostream.h>

int * getInt(char * str)
{
    int value=20;c
    cout<<str<<endl;
    return &value;
}

void somefn(char * str)
{
    int a=40;
    cout<<str<<endl;
}

int main()
{
    int * pr=getInt("input a value:");
    cout<<* pr<<endl;
    somefn("It is uncertain.");
    cout<<* pr<<endl;
}

搜索更多相关主题的帖子: 期望值 
2013-08-23 13:00
芦苇太帅了
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2013-8-16
得分:0 
二楼是对的,这个程序应返回一个局部变量的的地址而出错。
   大婶们,谢谢指导!
2013-08-25 13:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-419552-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.168656 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved