cvariablesscopeautomatic-variable

Are global variables in C automatic variables?


I was studying ANSI C programming language and it says in introduction:

"Local variables are typically "automatic," or created anew with each invocation."

I'm guessing allocating and deallocating variables work with stack frame logic of Java. So are global variables automatic too? They would get in and out of stack frame much less than local variables since they are in the scope of the whole .c file.


Solution

  • No, these concepts don't play each other. The term global variable is an informal notion, that refers to variables with external linkage. By definition, the automatic variables have no linkage, hence it does not make sense to have variable, that is both automatic and global.