In C programming, how many standard storage classes are there (considering classic C: auto, register, static, extern)?

Difficulty: Easy

Correct Answer: 4

Explanation:


Introduction / Context:
Storage classes in C describe the lifetime, visibility, and storage duration of identifiers. Understanding them is essential for reasoning about scope, linkage, and performance hints to the compiler.


Given Data / Assumptions:

  • Context: Classic C (not C++ extras like mutable; and 'typedef' is a type alias specifier, not a storage class).
  • Canonical set: auto, register, static, extern.


Concept / Approach:
Each storage class modifies how and where an object exists and how name resolution/linkage works across translation units.


Step-by-Step Solution:

auto: Default for block-scope objects; automatic storage duration; no external linkage.register: Hint that an object may be stored in a CPU register; still block scope; address-of may be restricted historically.static (at block scope): Static storage duration; preserves value across function calls; internal linkage by default at file scope if used with definitions.extern: Declares an object with external linkage defined elsewhere; does not allocate storage by itself (unless it is a tentative definition per older rules).


Verification / Alternative check:
Any C reference enumerates exactly these four storage classes for classic C. While modern standards refined semantics, the count remains 4 in this canonical sense.


Why Other Options Are Wrong:

  • 2: Omits multiple standard classes.
  • 3: Still incomplete (missing at least one of the four).
  • 6: Overcounts by including non-storage-class specifiers or C++-only concepts.


Common Pitfalls:

  • Misclassifying typedef as a storage class (it is a declaration specifier for type aliases).
  • Confusing C with C++ features such as mutable or thread_local in later standards.


Final Answer:
4

More Questions from Microprocessors

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion