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.

Hard 10 questions ~8 minutes Pass at 80% C17

Choose a mode

Playing as a guest: sign in to keep your XP and streak.

Sample question

Question 1 of 10

What 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

  • static local variables keep their value between calls
  • Static initializers run once and must be constant
  • static and extern at file scope (linkage)
  • Default zero initialization of static storage
  • register and 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.