Cheat sheet for storage classes and storage sections

Storage Classes & Sections in C

Storage Classes

INTRODUCTION
  • The storage class determines the part of memory where storage is allocated for an object (particularly variables and functions) and how long the storage allocation continues to exist.
  • A scope specifies the part of the program which a variable name is visible, that is the accessibility of the variable by its name. In C program, there are four storage classes: automatic, register, external, and static.
  • The hardware terms we have primary storage such as registers, cache, memory (Random Access Memory) and secondary storage such as Hard Disk and optical Disk.

Variables

Storage Section

Initial Value

Scope

Persistence

miscellaneous
Properties

Global initialized

Data

NA

Whole
program

Process

Global un-initialized

BSS

0

Whole
program

Process

Local initialized

Stack

NA

Block

Block

Local un-initialized

Stack

Garbage

Block

Block

Global static initialized

Data

NA

File

Process

Global static un-initialized

BSS

0

File

Process

Local static initialized

Data

NA

Block

Process

Local static un-initialized

BSS

0

Block

Process

Constants

text

NA

Block

Block

Command line arguments

text

NA

Block

Block

Dynamically allocated (malloc)

heap

Garbage

Whole
program

Process

Dynamically allocated (calloc)

heap

0

Whole program

Process

Automatic

stack

Garbage

Block

Block

Volatile

stack

Garbage

Block

Block

Only local variables

Register

stack

Garbage

Block

Block

Only local variables

Address can't printed

Extern

NA

No init

Block

Process

Only Global variables

Can be added to header files