Output-Based C Questions

Many C interviews start with "what does this print?". This quiz gives you short, complete C programs that test post-decrement loops, chained and compound assignments, nested ternaries, the comma operator and logical operators, so you can practise reading code the way the compiler does.

Medio 10 domande ~6 minuti Superato con il 80% C17

Scegli una modalità

Stai giocando come ospite: accedi per salvare XP e serie.

Domanda di esempio

Domanda 1 di 10

What does this print?

#include <stdio.h>

int main(void) {
    int n = 3;
    while (n--) {
        printf("%d ", n);
    }
    printf("| %d\n", n);
    return 0;
}
Mostra la risposta

B. 2 1 0 | -1 n-- tests the old value and then decrements, so the body sees 2, 1 and 0. The final test reads 0 (false) but still decrements, leaving n at -1.

Cosa copre questo quiz

  • while (n--) and where the counter ends up
  • break in nested loops
  • Chained and compound assignment
  • Nested ?: and the comma operator in for
  • Logical operators always give 0 or 1

Domande frequenti

Serve un account?

No. Chiunque può giocare. Accedi per salvare XP, serie, badge e cronologia.

Posso rifarlo?

Sì. Il tuo miglior punteggio resta salvato, e domande e risposte vengono mescolate ogni volta.