1️⃣ What is extern?

extern allows you to use a global variable defined in another C file.

In simple words:

extern tells the compiler:

“This variable exists somewhere else. Don’t create it again.”

It does NOT create memory.

It only declares that the variable exists.


2️⃣ Why Do We Need extern?

When programs become large, we split them into multiple files:

main.c
math.c
utils.c

Sometimes we want to share a global variable between them.

That is where extern is used.


3️⃣ Basic Example

File: data.c

int count = 10;   // Global variable (definition)

This actually creates memory.


File: main.c

#include <stdio.h>

extern int count;  // Declaration (no memory created)

int main() {
    printf("%d", count);
}