鉴于今天在CSDN 上有关于 error: static declaration of xxx follows non-static declaration 的文章并没有解决自己的问题 ,我发现有时在调用函数之前声明了这个函数,依旧会出现上述error
#include<stdio.h>
int main(){
int F(int x);
int a; scanf("%d",&a);
printf("%d",F(a));
int F(int x){
if(x==1)return 1;
return x+F(x-1); }
return 0; } 对于这个定义为函数int F(int x); 被写在了main 函数的内部 ,然而不能在一个函数中定义另一个函数。 对于此类错误一般的error显示为a function-definition is not allowed here before ‘{’ token
若使用递归,存在出现error: static declaration of xxx follows non-static declaration的可能。
将main 中的F函数定义移出main函数 即可
#include<stdio.h>
int main(){
int F(int x);
int a;
scanf("%d",&a);
printf("%d",F(a)); }
int F(int x){
if(x==1)return 1;
return x+F(x-1);
}return 0;
}