Where is the name visible?
Inside a block, function or source file.
Storage classes help describe scope, storage duration, linkage and initialization behavior.
Inside a block, function or source file.
For one block execution or for the whole program.
Important for file-scope static and extern.
Automatic locals are indeterminate; static-duration objects start at zero.
auto - ordinary local | register - optimization hint | static - persistent storage | extern - defined elsewherecount is visible here.
The count declared inside show() cannot be accessed by name from main().
| Declaration | Scope | Storage duration | Main effect |
|---|---|---|---|
static int count;inside a function | Block | Entire program | Retains value between calls |
static int total;outside functions | File | Entire program | Internal linkage: name is limited to that source file |
extern int total; normally declares the same object; it does not create a second independent variable. Keep compilation and linking details for a later lecture.| Form | Where used | Lifetime | Main idea |
|---|---|---|---|
auto | Inside a block | Current block execution | Default ordinary local variable |
register | Inside a block | Current block execution | Compiler hint; address cannot be taken |
local static | Inside a block | Entire program | Retains value between calls |
file static | Outside functions | Entire program | Name restricted to that source file |
extern | Usually file scope | Refers to a static-duration object | Object is defined elsewhere |
Question 1 of 4
register is only a hint, and the compiler may ignore it.extern declaration normally refers to an object defined elsewhere.Exists during execution of its block.
Automatic local whose address cannot be taken.
Retains value or limits file-scope linkage.
Declares an object or function provided elsewhere.
Scope tells where a name is visible. Storage duration tells how long the object exists.