- Executors
-
Learn
Learn Python Runnable examples, NumPy, pandas, and more Learn AI / Machine LearningNeural networks, ML and LLMs from scratch Learn C & C++ Pointers, memory, STL, and modern C++ Learn C#C# basics, OOP, LINQ, async, and .NET exercises Learn MatplotlibLine, bar, scatter and pie charts with live visualizers Learn RustOwnership, traits, error handling, and threads Learn GoSlices, interfaces, goroutines, and channels Python Algorithms Search, sorting, recursion, and visualizers O(n) C & C++ Algorithms Compare algorithms implemented in C and C++ Coding for Kids Learn to code by playing!
- QuizzesNew
- ChallengesNew
- For TeachersNew
- Updates
- Buy me a coffee
static & Storage Classes
This C quiz digs into storage classes, the keywords that decide how long a variable lives and who can see it. You will trace static local counters, reason about default initialization and linkage, and spot code that breaks the rules for static and register.
Sample question
Question 1 of 10What does this print?
#include <stdio.h>
int next(void) {
static int n = 0;
n++;
return n;
}
int main(void) {
int a = next();
int b = next();
int c = next();
printf("%d %d %d\n", a, b, c);
return 0;
}
Show the answer
C. 1 2 3 A static local is created once, before the program starts, and keeps its value between calls. static int n = 0; is not run again on each call, so n goes 1, 2, 3.
What this quiz covers
staticlocal variables keep their value between calls- Static initializers run once and must be constant
staticandexternat file scope (linkage)- Default zero initialization of static storage
registerand why its address cannot be taken
Questions people ask
Do I need an account?
No. Anyone can play. Sign in to keep your XP, streak, badges and history.
Can I retake it?
Yes. Your best score is kept, and the questions and answers are shuffled each time.