In C89 all the declaration of local variables must be placed at the beginning of the statements or block
In short, all variable declarations must come first before you write a statement in the block or a function
To clarify, let’s see an example
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a=100; //Declaration of a local variable a
printf("%d\n",a);
int b=200; //Declaration of a local variable b
printf("%d\n",b); //Error With C89
return 0;
}
With C99 we can mix the declaration of a variable with the statements
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a=100; //Declaration of a local variable a
printf("%d\n",a);
int b=200; //Declaration of a local variable b
printf("%d\n",b); //not an Error With C99
return 0;
}
Leave a Reply