Thursday, February 20, 2014

Static Variable

static with init value -> .data
others -> .bss
i -> stack


In computer programming, a static variable is a variable that has been allocated statically -whose 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.

When a 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.