Storage Classes in C MCQ Quiz
Storage classes in C determine the scope, lifetime, visibility, and memory location of variables and functions. Understanding storage classes is essential for writing efficient programs and is a frequently asked topic in C programming interviews, Embedded Systems jobs, and technical assessments.
This Storage Classes in C MCQ Quiz contains carefully selected multiple-choice questions that help students and professionals evaluate their understanding of variable behavior in C programs.
Why Learn Storage Classes in C?
Storage classes play a critical role in memory management and program execution. They help programmers control:
- Variable scope
- Variable lifetime
- Memory allocation
- Accessibility across source files
- Program performance
The four primary storage classes in C are:
A strong understanding of these concepts is essential for Embedded Systems development, firmware programming, Linux device driver development, and general software engineering.
Storage Classes in C MCQ Questions and Answers
Question 1
What is the default storage class of a local variable in C?
a) static
b) extern
c) auto
d) register
Answer:
✅ c) auto
Explanation:
Local variables declared inside a function automatically belong to the auto storage class unless specified otherwise. These variables are created when the function starts execution and destroyed when the function exits.
Question 2
Which storage class retains the value of a variable between function calls?
a) auto
b) register
c) static
d) extern
Answer:
✅ c) static
Explanation:
A static variable is initialized only once and retains its value throughout the entire program execution, even after the function exits.
Question 3
What is the default value of a static variable if it is not explicitly initialized?
a) Garbage value
b) NULL
c) 0
d) 1
Answer:
✅ c) 0
Explanation:
Static variables are stored in the data segment and are automatically initialized to zero if no explicit value is assigned.
Question 4
Which storage class is used to access a global variable defined in another source file?
a) auto
b) register
c) static
d) extern
Answer:
✅ d) extern
Explanation:
The extern storage class tells the compiler that the variable is defined elsewhere and allows access across multiple source files.
Question 5
Where are auto variables typically stored?
a) Heap
b) Stack
c) Data Segment
d) CPU Register
Answer:
✅ b) Stack
Explanation:
Auto variables are generally stored in stack memory and exist only during the execution of the function where they are declared.
Question 6
Which of the following statements about register variables is true?
a) They always reside in CPU registers.
b) Their address can always be obtained using &.
c) They are suggested to be stored in CPU registers for faster access.
d) They retain their value between function calls.
Answer:
✅ c) They are suggested to be stored in CPU registers for faster access.
Explanation:
The register keyword is a request to the compiler to store the variable in a CPU register for faster access. The compiler may ignore this request if registers are unavailable.
Question 7
What will be the output of the following code?
void fun()
{
static int x = 0;
x++;
printf("%d ", x);
}
int main()
{
fun();
fun();
fun();
}
a) 1 1 1
b) 0 1 2
c) 1 2 3
d) 3 3 3
Answer:
✅ c) 1 2 3
Explanation:
The variable x is static, so it retains its value between function calls. The value increases with each call.
Question 8
Which storage class restricts a global variable’s visibility to the current source file?
a) extern
b) auto
c) register
d) static
Answer:
✅ d) static
Explanation:
A static global variable has internal linkage and can only be accessed within the source file in which it is declared.
Question 9
Which storage class does not allocate new memory for a variable?
a) auto
b) static
c) register
d) extern
Answer:
✅ d) extern
Explanation:
The extern declaration references an already existing variable rather than creating a new memory location.
Question 10
Which storage classes have a lifetime equal to the entire program execution?
a) auto and register
b) static and extern
c) auto and static
d) register and extern
Answer:
✅ b) static and extern
Explanation:
Variables declared using static and extern storage classes remain alive throughout the execution of the program.
Quick Revision Table
| Storage Class | Scope | Lifetime | Default Value |
|---|
| Auto | Local | Function Execution | Garbage Value |
| Static | Local/Global | Entire Program | 0 |
| Extern | Global | Entire Program | 0 |
| Register | Local | Function Execution | Garbage Value |
Real-World Applications of Storage Classes in C
Understanding storage classes is important in:
Engineers frequently use static variables to retain state information, extern variables for cross-file communication, and register variables in performance-critical sections.
Key Takeaways
- Auto is the default storage class for local variables.
- Static variables preserve values between function calls.
- Extern allows access to global variables across files.
- Register suggests faster access using CPU registers.
- Storage classes determine scope, lifetime, visibility, and memory allocation.
- Storage class questions are commonly asked in Embedded Systems and C programming interviews.
Conclusion
This Storage Classes in C MCQ Quiz helps students, job seekers, and Embedded Systems enthusiasts assess their understanding of one of the most important concepts in C programming. Regularly practicing MCQ questions on storage classes improves problem-solving skills and strengthens interview preparation.
Continue practicing C programming quizzes to master memory management, variable scope, and program execution concepts that are essential in software and Embedded Systems development.
