33,311
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include<iostream>
using namespace std;
int &foo(int a)
{
static int t;
t=a;
return t;
}
void main()
{
cout<<foo(1)<<endl;
cout<<foo(2)<<endl;
if (foo(1) + 1 == foo(2) + 1) //此时会保存临时变量,而不是直接比对t的值,所以为false
{
cout<<foo(1)<<endl; //输出 1
cout<<foo(2)<<endl; //输出 2 问题2:程序既然判断两个值相等,输出值又不一样。
cout<<"相等";
}
else
cout<<"不相等";
getchar();
}