64,654
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string.h>
//在一个函数中返回一个引用变量b,是可行的,但是如果直接返回a,则不可取,因为a是一个临时变量。
int & func2(){
int a = 20;
int &b = a;
printf("a = %d %p, &b = %d %p\n",a,&a,b,&b);
return b;
}
int main(){
int x = 0;
x = func2();
printf("x = %d %p\n",x,&x);
return 0;
}
int & func2(){
int a = 20;
int &b = a;
printf("a = %d %p, &b = %d %p\n",a,&a,b,&b);
return a;
}