C Programming Tutorial 0/65 lessons ~6 min read Lesson 58
Storage Classes
Storage classes — auto (local default), register (hint), static (persistent/block scope), extern (global linkage).
Course progress0%
Focus
9 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
Storage classes — auto (local default), register (hint), static (persistent/block scope), extern (global linkage).
Understanding the topic
static local Retains value between function calls.
extern Declares symbol defined elsewhere.
- static local — Retains value between function calls.
- extern — Declares symbol defined elsewhere.
Step-by-step explanation
- static local — Retains value between function calls.
- extern — Declares symbol defined elsewhere.
Informative example
Example program:
c
#include <stdio.h>void counter(void) {static int count = 0;count++;printf("%d\n", count);}int main(void) {counter(); counter(); counter();return 0;}
Output
1 2 3
Execution workflow
1Storage Classes — step by step
1 / 2static local
Retains value between function calls.
Best practices
- Enable warnings: gcc -Wall -Wextra -std=c11 source.c -o app
- Give every variable a defined value before it is read.
- Stay inside array bounds — C will not stop you from over-running a buffer.
Common mistakes
- Reading uninitialized storage — behavior is undefined.
- Dismissing compiler warnings instead of fixing root causes.
- Ignoring NULL returns from malloc, fopen, and similar APIs.
Hands-on exercise
Practice problems:
- static vs auto local
- extern variable in two files
Summary
Storage Classes in C — auto, register, static, extern — lifetime and visibility.
Ready to mark this lesson complete?Track your journey across the entire course.