extern?extern allows you to use a global variable defined in another C file.
In simple words:
externtells the compiler:“This variable exists somewhere else. Don’t create it again.”
It does NOT create memory.
It only declares that the variable exists.
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.
int count = 10; // Global variable (definition)
This actually creates memory.
#include <stdio.h>
extern int count; // Declaration (no memory created)
int main() {
printf("%d", count);
}