1️⃣ What is a Static Variable?

A static variable:


2️⃣ Example: Static Variable Inside a Function

#include <stdio.h>

void test() {
    static int x;
    x++;
    printf("%d\\n", x);
}

int main() {
    test();
    test();
    test();
}

Output:

1
2
3

🔎 Why is the Output 1 2 3?

Step-by-step understanding:

The key idea:

Static variable keeps its value even after the function ends.