Static Variable in C
Level 4113 keystrokes
Uses a static variable to preserve value between function calls.
C code
// Function with static variable1void counter() { // The static variable is initialized only once // and keeps its value between calls2 static int count = 0; // Increment the counter3 count++; // Print current count4 printf("Count: %d\n", count);5}6 // First call: count becomes 17counter();// Second call: count becomes 28counter();// Third call: count becomes 39counter();Output
Count: 1 Count: 2 Count: 3
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C code and how often they appear.
;× 6(× 5)× 5"× 2+× 2,× 1:× 1{× 1}× 1\× 1