Possible Duplicate:
Variable declaration placement in C
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]);
}
}
But if I put declaration at beggining, above the array, it works.
Looks like you are compiling in ANSI C mode. In C89, variable declaration is allowed only at the beginning of a block.
Since C99, this restriction has been removed. Compile with -std=c99
which will allow you to declare variables anywhere.
as far as i know in C, all declarations must be above the code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With