How many storage classes are there in C?
Analysis & Theory
C provides four storage classes: `auto`, `register`, `static`, and `extern`.
What is the default storage class for local variables?
Analysis & Theory
`auto` is the default storage class for all local (block scope) variables.
Which storage class makes a local variable retain its value between function calls?
Analysis & Theory
`static` gives the variable a lifetime equal to the program, but limits scope to the block.
What does the `register` storage class suggest to the compiler?
A
Store variable in stack
C
Store in CPU register for faster access
Analysis & Theory
`register` requests the variable to be stored in a CPU register if available (not guaranteed).
Which of these storage classes can be used to define a global variable in one file and access it in another?
Analysis & Theory
`extern` is used for declaring a variable defined elsewhere (usually in another file).
What is the scope of an `auto` variable?
Analysis & Theory
`auto` variables are local to the block or function in which they are declared.
Which storage class cannot be used for global variables?
Analysis & Theory
`auto` is only used for local variables and cannot be used for global variables.
What is the lifetime of a `static` variable declared inside a function?
A
Until the function ends
Analysis & Theory
`static` variables persist for the entire duration of the program.
Which of the following **limits variable visibility to the same file**?
Analysis & Theory
`static` at file scope restricts visibility of functions/variables to the same source file.
Which storage class is mainly used for **header file declarations**?
Analysis & Theory
`extern` is used to declare variables that are defined in other files.