/*
*Copyright (c)2014,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:C++.cpp
*作 者:王一锟
*完成日期:2014年12月1日
*版 本 号:v1.0
*
*问题描述:
*输入描述:
*输出描述:
*/
#include <iostream>
using namespace std;
int f(int n);
int main()
{
cout<<f(5)<<" ";
cout<<f(8)<<endl;
return 0;
}
int f(int n)
{
static int a=2;
int b=0;
a+=n;
b+=a;
return b;
}
运行结果:
static变量在函数中的应用:跳出函数时保留运行后static变量的结果。