Quiz de C: 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.

Difícil 10 perguntas ~8 minutos Aprovação com 80% C17

Escolha um modo

Jogando como visitante: entre para guardar seu XP e sua sequência.

Pergunta de exemplo

Pergunta 1 de 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;
}
Mostrar a resposta

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.

O que este quiz cobre

  • 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

Perguntas frequentes

Preciso de uma conta?

Não. Qualquer pessoa pode jogar. Entre para guardar seu XP, sequência, badges e histórico.

Posso refazer?

Pode. Sua melhor nota fica salva, e as perguntas e respostas são embaralhadas a cada vez.