C Memory Bugs Quiz

Manual memory management is where most serious C bugs come from. This hard quiz shows short programs with leaks, double frees, dangling pointers and buffer overruns, and asks you to name the bug and the fix, just like a code review or a C interview.

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 is wrong with this code?

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    for (int i = 0; i < 3; i++) {
        char *buf = malloc(64);
        if (buf == NULL) return 1;
        snprintf(buf, 64, "line %d", i);
        printf("%s\n", buf);
    }
    return 0;
}
Show the answer

C. Memory leak: each buf is never freed Every iteration allocates a new block and loses the pointer at the end of the loop body, so three blocks leak. Add free(buf); after the printf(), or allocate once before the loop.

What this quiz covers

  • Memory leaks in loops and when a pointer is overwritten
  • Use after free and dangling pointers
  • Double free and freeing memory that was not allocated
  • Off-by-one allocations for strings
  • Tools that catch these bugs at runtime

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.