![]() |
static | Keyword |
Keyword Index |
Preserves variable value to survive after its scope ends.
Keyword static
may be applied to both data and function definitions:
static data-definition; static function-definition;For example,
static int i = 10; static void PrintCR (void) { putc ('\n'); }
static
tells that a function or data element is only known within the scope of the current
compile. In addition, if you use the static
keyword with a variable that is
local to a function, it allows the last value of the variable to be preserved between
successive calls to that function.
static
keyword) are initialized during the run-time, so the initialization will be executed whenever
it is encountered in the program. Static (and global) variables are initialized during
the compile-time, so the initial values will simply be embeded in the executable
file itself. If you change them, they will retain changed in the file. By default, the C language
proposes that all uninitialized static variables are initialized to zero, but due to some
limitations in TIGCC linker, you need to initialize explicitely all static and global variables
if you compile the program in "nostub" mode.
int a = 10;and if you change its value somewhere in the program to 20 (for example), its initial value will be 20 (not 10) on the next program start! Note that this is true only for global and static variables. To force reinitializing, you must put explicitely something like
a = 10;at the begining of the main program!