C: Find the Bug

This C quiz is a code review in ten questions. Each program contains a bug that compiles (or almost does), from missing braces to char holding EOF, and you have to say what really happens and how to fix it.

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

The withdrawal is smaller than the balance, so the author expects 50. What does this print?

#include <stdio.h>

int main(void) {
    int balance = 100, amount = 50;
    if (amount > balance)
        printf("declined ");
        amount = 0;
    balance -= amount;
    printf("%d\n", balance);
    return 0;
}
Mostrar a resposta

C. 100 Without braces only the first statement belongs to the if. amount = 0; always runs despite its indentation, so nothing is withdrawn; wrap both lines in { }.

O que este quiz cobre

  • Missing braces and off-by-one loop bounds
  • Integer division in percentages
  • Unsigned results from strlen() subtraction and floating point equality
  • getchar() into a char, uninitialised totals and sizeof on a heap pointer
  • The overflow in (low + high) / 2

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.