C++引用:经典例题之引用作为函数的返回值,结合函数栈帧详解

来源:互联网 发布:控制算法工程师面试题 编辑:程序博客网 时间:2024/06/01 08:17

代码如下:

#include <stdio.h>#include <windows.h>#include <iostream>using namespace std;int& fun(){    int a = 10;    return a;}int main(){    int &b = fun();    printf("%d\n", b);    printf("%d\n", b);    printf("%d\n", b);    system("pause");    return 0;}

输出结果如图:
这里写图片描述
详解如图:(如果看不清楚图片,请右键图片选择“在新标签页中打开图片”,即可查看清晰大图)
这里写图片描述

原创粉丝点击