1️⃣ The Idea: Counting How Many Times a Function Runs

Sometimes we want to track:

To do this, we need a variable that:

That’s where global and static variables help.


2️⃣ Using a Global Variable for Counting

#include <stdio.h>

int count = 0;   // global variable

void test() {
    count++;
    printf("%d\\n", count);
}

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

Output:

1
2
3

Why it works:


🔁 Alternative: Count Globally, Print Only Once