内容来自
http://topic.youkuaiyun.com/u/20110915/22/58f0894c-e125-499b-b5ab-6a6398193293.html
// Domain.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int a=4;
int f(int n)
{
int t=0; static int a=5;
if(n%2)
{
int a=6;
t+=a++; //D
}
else
{
int a=7;
t+=a++; //B:t=7
}
return t+a++; //C:t=7+5,然后a自加变成6 //E
}
void main()
{
int s=a,i=0; //A:a=4;
for(;i<2;i++)
{
s+=f(i); //4+f(0)+f(1)=4+7+5+f(1)
}
printf("%d\n",s);
}
//4+7+5+6+6
本文通过一个C++程序示例介绍了局部变量与静态变量的作用范围及使用方式,展示了不同作用域变量如何影响函数返回值,并通过主函数调用进行了结果展示。
313

被折叠的 条评论
为什么被折叠?



