Nope, a
has local scope (declared between brackets) so at the closing brace it will be cleaned up.
If you want it to persist for the entirety of the program, either declare it as static
or put it outside of any braces, preferably before you use it.
This has the added benefit of having the compiler initialise it for you.
You can try out the following:
#include <stdio.h>
int a;
int main()
{
static int b;
int c;
printf("%d, %d, %d\n", a, b, c); /* a and b should print 0, printing c is undefined behaviour, anything could be there */
return 0;
}
As Bathsheba pointed out, static
variables should be used judiciously if used in a multi-threaded environment.