标题:返回堆空间地址引用的问题
取消只看楼主
后生无畏
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-10-9
 问题点数:0 回复次数:0 
返回堆空间地址引用的问题
#include <iostream.h>
#include <malloc.h>
int* & fun1()
{
    int* ps=new int;
    //int* ps=ps1;
    *ps=2;
    return ps;
}
void main()
{
    int* ps=fun1();  
    cout<<*ps<<endl;
}
为什么返回堆空间地址的引用, ps的值在函数返回前后不一样? 但是如果先把ps赋值给变量ps1,再返回
ps1的引用,这样就没问题,这是为什么?请高人指教
搜索更多相关主题的帖子: 空间 地址 
2008-10-09 21:55



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




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

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