有以下程序#include<stdio.h>int f(int m){static int n=0; n+=m: return n;}main(){ int
有以下程序
#include<stdio.h>
int f(int m)
{ static int n=0;
n+=m:
return n;
}
main()
{ int n=0;
printf("%d,",f(n));
printf("%d\n",f(n++));
}
程序运行后的输出结果是
A.1,2
B.1,1
C.2,3
D.3,3
A
解析:static变量用于局部变量中有记忆功能和全局生存期。函数中的静态变量的特点是每次调用函数,静态变量的值是上次调用完该函数后的静态变量值,所以在此题中,第一调用函数,返回1,此时函数中的静态变量n的值为l,所以第二次调用函数时,返回值为2。