C变量声明的地方 [英] C variable declaration place
问题描述
可能重复:结果
用C 变量声明安置
Possible Duplicate:
Variable declaration placement in C
我真的不明白,为什么当我在下面,为什么它不工作文档片断code声明变量M状???我声明米之前,我用它有啥点?谢谢
I really dont understand why when I declare variable 'm' like in snipped code below why it doesn't work???I declare m before I use it so what's the point?? thanks
int main(){
int a[] = {2,-4,6,47,59,-6,0};
sort(a, 7);
int m;
for(m = 0; m < 7; m++){
printf("%d ",a[m]);
}
}
但是,如果我把宣言beggining,数组上面,它的工作原理。
But if I put declaration at beggining, above the array, it works.
推荐答案
看起来你是在ANSI C模式下编译。在C89,变量声明仅在一个块的开头不允许的。
Looks like you are compiling in ANSI C mode. In C89, variable declaration is allowed only at the beginning of a block.
由于C99,这一限制已被删除。与 -std = C99
编译,让您在任何地方声明变量。
Since C99, this restriction has been removed. Compile with -std=c99
which will allow you to declare variables anywhere.
这篇关于C变量声明的地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!