Static Counter Demo
C
Easy
4 views
Problem Description
Create a function that counts the number of times it has been called on each call. Implement it using a static variable. Call main 10 times and display the count.
Official Solution
#include <stdio.h>
void callCounter() {
static int count = 0; // static variable
count++;
printf("Function called %d timesn", count);
}
int main() {
int i;
for (i = 1; i <= 10; i++) {
callCounter();
}
return 0;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!