c语言 函数参数只能是自动局部变量,不能是静态局部变量,为什么?

如题所述

伪命题,静态局部变量可以当做函数参数。

举个反例推翻该命题:

#include <stdio.h>
void f(int n)
{
printf("%d", n*n);
}
int main()
{
static int n=2;
f(n);  //n是静态局部变量,OK
return 0;
}

追问

emmmmmm..这是书上的题目。。

追答

要么是你描述的不对,要么那书呵呵了

#include <stdio.h>
void f(static int n)  //这样都可以,虽然没什么用
{
printf("%d", n*n);
}
int main()
{
 static int n=2;
f(n);  //n是静态局部变量,OK
return 0;
}

温馨提示:答案为网友推荐,仅供参考
相似回答