C-Quiz: Buffer Overflows & Bounds

C does not check array bounds, so one wrong index can corrupt memory or open a security hole. This quiz shows realistic snippets and asks you to spot off-by-one errors, unsafe string calls and sneaky signed/unsigned comparisons, and pick the safe fix.

Schwer 10 Fragen ~8 Minuten Bestanden ab 80% C17

Modus wählen

Du spielst als Gast: Melde dich an, damit XP und Serie gespeichert werden.

Beispielfrage

Frage 1 von 10

What is the bug in this code?

#include <stdio.h>

int main(void) {
    int a[5];
    for (int i = 0; i <= 5; i++) {
        a[i] = i * i;
    }
    printf("%d\n", a[4]);
    return 0;
}
Lösung zeigen

D. i <= 5 writes to a[5], one element past the end A 5-element array has indexes 0 to 4, so the last iteration writes a[5], outside the array. The fix is i < 5; the <= off-by-one is one of the most common overflow causes.

Darum geht es in diesem Quiz

  • Off-by-one loops and the missing terminator byte
  • What undefined behaviour means for an out-of-bounds write
  • Unsafe calls: gets, strcpy without a size check
  • Bounded alternatives: fgets, snprintf, explicit checks
  • Finding bugs with -fsanitize=address

Häufige Fragen

Brauche ich ein Konto?

Nein. Jeder kann spielen. Mit Anmeldung werden XP, Serie, Abzeichen und Verlauf gespeichert.

Kann ich es wiederholen?

Ja. Dein Bestwert bleibt erhalten, und Fragen und Antworten werden jedes Mal neu gemischt.