Difference between revisions of "Static variable"
Karl Jones (Talk | contribs) (Created page with "In computer programming, a '''static variable''' is a variable that has been allocated statically so that its lifetime or "extent" extends...") |
(No difference)
|
Latest revision as of 14:32, 26 August 2016
In computer programming, a static variable is a variable that has been allocated statically so that its lifetime or "extent" extends across the entire run of the program.
This is in contrast to the more ephemeral automatic variables (local variables are generally automatic), whose storage is allocated and deallocated on the call stack; and in contrast to objects whose storage is dynamically allocated in heap memory.
Description
Static memory allocation in general is the allocation of memory at compile time before the associated program is executed, unlike dynamic memory allocation or automatic memory allocation where memory is allocated as required at run time.
The absolute address addressing mode can only be used with static variables, because those are the only kinds of variables whose location is known by the compiler at compile time.
When the program (executable or library) is loaded into memory, static variables are stored in the data segment of the program's address space (if initialized), or the BSS segment (if uninitialized), and are stored in corresponding sections of object files prior to loading.
The static
keyword is used in C and related languages both for static variables and other concepts.
See also
- Constant (computer programming)
- Global variable
- Run time (program lifecycle phase)
- Static method
- Thread-local storage
External links
- Static variable @ Wikipedia