-
Notifications
You must be signed in to change notification settings - Fork 2
Types
... when we have "declared" a variable, we have meant that we have told the compiler about the variable; i.e. its type and its name, as well as allocated a memory cell for the variable (either locally or globally). This latter action of the compiler, allocation of storage, is more properly called the definition of the variable. The stricter definition of declaration is simply to describe information ``about'' the variable.
For automatic and register variables, there is no difference between definition and declaration. However, for external variables, these two operations may occur independently.
It depends on a lot of factor. The compiler can optimize and remove it from the stack, keeping the value in register. etc.
3.2.1 Memory Allocation in C Programs
Automatic allocation happens when you declare an automatic variable, such as a function argument or a local variable. The space for an automatic variable is allocated when the compound statement containing the declaration is entered, and is freed when that compound statement is exited. In GNU C, the size of the automatic storage can be an expression that varies. In other C implementations, it must be a constant.