c++求解!!!!!!!!!!

[复制链接]
查看11 | 回复2 | 2010-6-22 16:54:37 | 显示全部楼层 |阅读模式
#include
using namespace std;
int d=1;
fun (int p)
{ static int d=5;
d+=p;
cout<<d;
return (d);
}
int main( )
{ int a=3;
cout<<fun(a+fun(d))<<endl;
return 0; }
麻烦咯
麻烦详细解答

回复

使用道具 举报

千问 | 2010-6-22 16:54:37 | 显示全部楼层
这题主要是考你关键字static~~~哥哥帮你分析下:#include using namespace std;int d = 1;//这是全局变量,作用域为整个程序.fun (int p){ static int d = 5;//这是静态局部变量, 只对函数内可见, 但是是存在静态区, 不会随着函数的结束而释放, 直到程序结束! d += p; cout<<d; return (d);}int main( ){int a = 3; cout<<fun(a+fun(d))<<endl; return 0; }过程详细分析:
回复

使用道具 举报

千问 | 2010-6-22 16:54:37 | 显示全部楼层
61515 fun(d)→fun(1)→d=6 fun(a+6)→fun(9)→d=6+9=15,返回15
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行