C

C Tutorial — Learn C Programming

Key takeaway: This free C tutorial teaches you systems programming from scratch — variables, pointers, arrays, functions, structs, and memory management — with practical code examples you can compile and run.

C is a general-purpose, procedural programming language created in 1972. It is used for operating systems, embedded systems, game engines, and performance-critical applications. This tutorial is for beginners, CS students, and developers who want to understand how computers work at a low level.

Last updated: September 2026

Storage Classes in C

Storage classes define the scope, visibility, and lifetime of variables and functions in C. They determine where variables are stored in memory and how long they persist.

auto Storage Class

Automatic Variables (Default)
#include <stdio.h>

void function() {
    auto int x = 10;  // auto keyword (optional)
    int y = 20;       // Same as auto int y = 20;
    
    printf("Inside function: x = %d, y = %d\n", x, y);
    x++;
    y++;
    printf("After increment: x = %d, y = %d\n", x, y);
}

int main() {
    function();
    function();  // Variables are reinitialized each call
    
    // auto variables are destroyed when function ends
    // printf("%d", x);  // Error: x not accessible here
    
    return 0;
}

static Storage Class

Static Variables
#include <stdio.h>

void counter() {
    static int count = 0;  // Initialized only once
    count++;
    printf("Function called %d times\n", count);
}

static int globalStatic = 100;  // File scope only

void showGlobal() {
    printf("Global static variable: %d\n", globalStatic);
    globalStatic++;
}

int main() {
    printf("Demonstrating static local variables:\n");
    counter();  // Output: 1
    counter();  // Output: 2
    counter();  // Output: 3
    
    printf("\nDemonstrating static global variables:\n");
    showGlobal();  // Output: 100
    showGlobal();  // Output: 101
    
    return 0;
}

extern Storage Class

External Variables
// file1.c
#include <stdio.h>

int globalVar = 50;  // Global variable definition

void printFromFile1() {
    printf("From file1: globalVar = %d\n", globalVar);
}

// file2.c (separate file)
#include <stdio.h>

extern int globalVar;  // Declaration (defined in file1.c)

void printFromFile2() {
    printf("From file2: globalVar = %d\n", globalVar);
    globalVar += 10;
}

// main.c
#include <stdio.h>

extern int globalVar;  // Declaration
extern void printFromFile1();  // Function declaration
extern void printFromFile2();  // Function declaration

int main() {
    printf("Initial value: %d\n", globalVar);
    
    printFromFile1();
    printFromFile2();
    
    printf("Final value: %d\n", globalVar);
    
    return 0;
}

register Storage Class

Register Variables (Hint to Compiler)
#include <stdio.h>

int main() {
    register int i;  // Suggest storing in CPU register
    register int sum = 0;
    
    // Frequently used variables in loops
    for (i = 1; i <= 1000; i++) {
        sum += i;
    }
    
    printf("Sum of 1 to 1000: %d\n", sum);
    
    // Note: Cannot take address of register variables
    // printf("Address: %p", &i);  // Error!
    
    return 0;
}

Storage Class Comparison

Complete Example
#include <stdio.h>

// Global variables
int globalVar = 100;           // External linkage
static int fileStatic = 200;   // Internal linkage

void demonstrateStorage() {
    auto int autoVar = 10;        // Automatic storage
    static int staticVar = 20;    // Static storage
    register int regVar = 30;     // Register storage (hint)
    
    printf("\nInside function:\n");
    printf("Auto variable: %d\n", autoVar);
    printf("Static variable: %d\n", staticVar);
    printf("Register variable: %d\n", regVar);
    printf("Global variable: %d\n", globalVar);
    printf("File static variable: %d\n", fileStatic);
    
    // Modify variables
    autoVar++;
    staticVar++;
    regVar++;
    globalVar++;
    fileStatic++;
    
    printf("\nAfter increment:\n");
    printf("Auto variable: %d\n", autoVar);
    printf("Static variable: %d\n", staticVar);
    printf("Register variable: %d\n", regVar);
    printf("Global variable: %d\n", globalVar);
    printf("File static variable: %d\n", fileStatic);
}

int main() {
    printf("Storage Class Demonstration\n");
    printf("===========================\n");
    
    printf("First function call:");
    demonstrateStorage();
    
    printf("\nSecond function call:");
    demonstrateStorage();
    
    printf("\nThird function call:");
    demonstrateStorage();
    
    return 0;
}
Storage Class Summary:
  • auto: Default for local variables, automatic lifetime
  • static: Preserves value between function calls, file scope for globals
  • extern: Declares variables defined in other files
  • register: Suggests CPU register storage (compiler hint)

Frequently Asked Questions

C is a foundational systems programming language that's been around since the 1970s. It's the base for Linux, Windows, and most operating systems. Learning C gives you deep understanding of memory, pointers, and how computers work — skills that transfer to every other language. According to the TIOBE Index, C consistently ranks in the top 2 most popular languages.

No, zero experience needed. Our C programming tutorial is designed for complete beginners. We start with Hello World and gradually progress to pointers and memory management. Basic computer literacy and logical thinking are helpful but not required.

Just a C compiler — or use our free online compiler. For beginners, our online C compiler requires no installation. For local development, use GCC (available on all platforms). IDEs like VS Code, Code::Blocks, or Dev-C++ also work well.

2–4 weeks for basics, 3–6 months for proficiency. With 1–2 hours daily practice, you can learn syntax, loops, and functions in a few weeks. Mastering pointers, memory management, and data structures takes 6–12 months. Practice with our C programming examples.

C programming skills open doors to various career paths including system programming, embedded systems development, operating system development, device driver programming, game development, and firmware development. Many companies in automotive, aerospace, telecommunications, and IoT sectors actively seek C programmers.

Yes, extremely relevant. C consistently ranks in the top 2 on TIOBE and powers Linux, embedded systems, IoT, automotive software, and game engines. Understanding C makes you a better programmer in any language since most runtimes (Python, Java, Node.js) are themselves written in C.