C MoreLesson 53Free preview
C Storage Classes
This lesson is part of C · All levels
Summary
Storage class determines where a variable comes from, how long it lives, and how far it can be seen. C identifies auto as the default local variable, static for values that persist between calls, register as an optimization guide, and extern for declarations to other files. This understanding is important to write the correct function, for example a function with a static type calculator.
Key points
- Auto is a native to a variable within a function and lives until the function is complete.
- Local static stores its value in data memory so it stays true even when the function is complete; global static is limited to that file.
- Extern marks that the definition of a variable or function is in another file.
- The register is just a clue to the compiler, and the modern compiler is free to ignore it.
- Lifetime static lasts during the program's run, while auto disappears when the function returns.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.