
c++函数返回引用
发布日期:2021-05-06 15:36:40
浏览次数:19
分类:原创文章
本文共 340 字,大约阅读时间需要 1 分钟。
下面的测试在vs2017顺利输出:
#include <iostream>#include <string>//C++int getAA1(){ int a = 10; return a;}int& getAA2(){ int a = 10; return a;}int* getAA3(){ int a = 10; return &a;}void main(){ int a1 = getAA1(); int &b = getAA2(); int *c = getAA3(); printf("a:%d,b:%d,c:%d \n", a1, b, *c); system("pause");}
但是调试到system时:
b,c指向的地址已经释放,不知道编译器是怎么做这件事的?
发表评论
最新留言
哈哈,博客排版真的漂亮呢~
[***.90.31.176]2025年03月29日 14时43分57秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!