These are declared inside a function or a block (between { }).
Scope: Only accessible within the function where they are defined.
Lifetime: They are created when the function starts and destroyed when it finishes.
Default Value: Contains "garbage" (random data) unless initialized.
These are declared outside of all functions, usually at the top of the program.
Scope: Accessible by any function throughout the entire program.
Lifetime: They exist for the entire duration of the program.
Default Value: Automatically initialized to 0.
Static variables are declared using the static keyword. They have a unique behavior:
Scope: If local, they stay within the function; if global, they stay within that specific file.
Lifetime: They retain their value between function calls. They are initialized only once.
Used when you want to share a variable across multiple files. The extern keyword tells the compiler that the variable is defined in another file.
| Variable Type | Keyword | Declaration Location | Scope | Lifetime |
| Local | None (default) | Inside a function | Function-level | Until function ends |
| Global | None (default) | Outside all functions | Program-wide | Until program ends |
| Static | static | Inside or Outside | Local/Global | Until program ends |
| External | extern |
Copyright ©2025. All Rights Reserved Emblab THE RAVE INNOVATION