Static variables
Check out this C code:
|
|
Output:
|
|
Cool, huh?
# Notes
Local static
variables have some benefits over global
variables. You can have multiple static
variables that are named the same, but used in different functions. And they’re isolated from other functions. Cool!
It’s impossible to have a static variable inside a struct. That defeats their whole purpose, as their variables are stored together, like in array. But it’s possible to have a static
struct!
A possible downside - the memory for static objects is allocated in the data segment. That means they’re not freed until the termination of a program.