Best Division

Spread Your Knowledge

  • All topics
  • About us
  • Contact us
  • Privacy policy
  • Terms of service
  • Copyright
  • Facebook
  • Twitter
  • Instagram
  • Youtube
  • LinkedIn
  • Pinterest
  • Github
  • Tumblr

© 2026 Best Division

What are storage classes in C: auto, register, extern, static?

C
Jayant Kumar
Jayant Kumar@jayantkumar314
PublishedNov 29, 2026
7 min read

Storage classes in C decide how long a variable lives, where it is visible, and where the compiler puts it. C has four storage-class specifiers you use in everyday code: auto, register, extern and static. Since C11 there is also _Thread_local, and C23 adds constexpr as a storage-class specifier for named constants.

Every object has two properties that storage classes control: its storage duration (automatic, static or thread) and its linkage (none, internal or external). Once you know those two ideas, the four keywords stop being a memorisation exercise.

Table of Contents

  • Scope, storage duration and linkage in plain words
  • The auto storage class
  • The register storage class
  • The static storage class
    • Static local variables keep their value
    • Static at file scope means internal linkage
  • The extern storage class
  • Default values and where each object lives
  • Thread-local storage in C11 and C23
  • Frequently Asked Questions
    • What is the default storage class in C?
    • Can a function be static?
    • What is the difference between a declaration and a definition with extern?
    • Is register still useful?
  • Summary
  • Related Articles

Scope, storage duration and linkage in plain words

Three terms come up in every discussion of storage classes in C.

  • Scope is the part of the source text where a name can be used: block scope (inside {}) or file scope (outside every function).
  • Storage duration is how long the object exists: automatic (until its block ends), static (the whole program run) or thread (the whole life of a thread).
  • Linkage says whether the same name in different places refers to the same object: none (a local name), internal (shared within one .c file) or external (shared across the whole program).
SpecifierDefault placeStorage durationLinkage
autoinside a blockautomaticnone
registerinside a blockautomaticnone
staticblock or filestaticnone (block) or internal (file)
externfile (or block)staticexternal, usually

The auto storage class

Every variable declared inside a function without another specifier is already auto. It is created when execution enters the block and destroyed when the block ends. Its value is indeterminate until you assign it.

c

Nobody writes auto in C code today, because it is the default. Note that in C23 and in C++11 and later, auto also means type inference (auto x = 5;), so keep the old meaning in mind only when reading legacy code.

The register storage class

register is a hint that a variable is used so often that it should live in a CPU register. Modern compilers ignore the hint and allocate registers better than you can. The one rule that remains is real: you cannot take the address of a register variable.

c

That restriction is the only practical effect. Write plain local variables and let the optimiser work.

The static storage class

static has two different meanings, depending on where you use it.

Static local variables keep their value

A static variable inside a function is created once, initialised once (to zero if you give no value), and lives for the entire program. The name is still visible only inside the function.

c
text

The initialiser of a static variable must be a constant expression. Static locals are shared by every call, so they are not thread-safe and make recursion harder to reason about.

Static at file scope means internal linkage

Placed on a global variable or a function, static hides the name from other source files. This is the standard way to make a file-private helper.

c

Another file can define its own calls without a clash, because each has internal linkage.

The extern storage class

extern declares that an object or function is defined somewhere else, usually in another file. A declaration says "this exists"; a definition actually reserves memory. You can declare many times but must define exactly once.

c

Functions at file scope are extern by default, so extern int add(int, int); and int add(int, int); mean the same. Do not write extern int x = 5; at file scope in a header: that is a definition, and including it in two files breaks the link step.

Default values and where each object lives

Objects with static storage duration (globals and static locals) are zero-initialised when you give no initialiser. Automatic objects are not.

c
text

Typical implementations keep automatic variables on the stack, and static-duration objects in the data or BSS segments. The standard does not mandate this layout, so rely on the duration rules, not the segments.

Thread-local storage in C11 and C23

_Thread_local (or thread_local from <threads.h>, and a keyword in C23) gives each thread its own copy of a variable with static-like lifetime. It can combine with static or extern.

c

C23 also lets you write constexpr int size = 16; to declare a compile-time constant object.

Frequently Asked Questions

What is the default storage class in C?

Local variables default to auto. Global variables and functions default to static storage duration with external linkage.

Can a function be static?

Yes. A static function has internal linkage, so only code in the same file can call it. Use it for helpers you do not want to expose.

What is the difference between a declaration and a definition with extern?

An extern declaration names an object defined elsewhere and allocates no memory. The definition, without extern and usually with an initialiser, appears in exactly one source file.

Is register still useful?

Almost never. Compilers decide register allocation themselves, and the keyword only forbids taking the variable's address.

Summary

Storage classes in C control lifetime and linkage. Use plain locals (implicitly auto) by default, static inside a function to keep state between calls, static at file scope to make names private, and extern to share a single global defined in one file. Treat register as obsolete, and use _Thread_local when each thread needs its own copy.

Related Articles

  • What Is the Scope and Lifetime of a Variable in C?
  • What is a static variable in C?
  • Learn C: Complete Study Roadmap from Beginner to Advanced
Share