Static Variables¶
Lifetime and Visibility (1)¶
Time span where a variable is alive (its address is valid)
The time of a function call $to$ automatic variable
The entire program
Visibility of a variable
Inside the where it is defined ⟶ internal Variable
Inside the file where is is defined
Across the entire programx
Automatic Variables¶
|
void f(void)
{
int i;
}
|
Local static
Variable¶
Visible only inside the function where it is defined
Retaines it value across function calls
|
void f(void)
{
static int i;
}
|
Global static
Variable¶
Visible only inside the file where it has been defined
Retains its value during program lifetime
|
static int i;
|
Global Variable¶
Visible across all files
Retains its value during program lifetime
|
int i;
|