I
Infinity
As far as I know, all variable declarations and definitions must
happen at the beginning of a block. However, with the gcc on my
system, variable declaration and definition at the middle of a block
also works. Why?
Example output below:
$ cat a.c
#include <stdio.h>
int main()
{
int a = 10;
printf("a = %d\n", a);
int b = 5;
printf("b = %d\n", b);
return 0;
}
inf@CYGWIN-LAPTOP ~
$ gcc -std=c89 a.c; ./a.exe
a = 10
b = 5
inf@CYGWIN-LAPTOP ~
$ gcc -std=c99 a.c; ./a.exe
a = 10
b = 5
happen at the beginning of a block. However, with the gcc on my
system, variable declaration and definition at the middle of a block
also works. Why?
Example output below:
$ cat a.c
#include <stdio.h>
int main()
{
int a = 10;
printf("a = %d\n", a);
int b = 5;
printf("b = %d\n", b);
return 0;
}
inf@CYGWIN-LAPTOP ~
$ gcc -std=c89 a.c; ./a.exe
a = 10
b = 5
inf@CYGWIN-LAPTOP ~
$ gcc -std=c99 a.c; ./a.exe
a = 10
b = 5