Quiz di C: Pointer Arithmetic

This C quiz tests how pointer arithmetic works: adding to a pointer moves by whole elements, subtracting two pointers counts elements between them, and * and ++ combine in ways that trip people up. You need to know basic pointers already.

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 a[] = {10, 20, 30, 40};
    int *p = a;
    p += 2;
    printf("%d\n", *p);
    return 0;
}
Mostra la risposta

C. 30 p starts at a[0], and adding 2 moves it two elements forward, to a[2]. Pointer arithmetic counts in elements, so the result is 30, not something 2 bytes further.

Cosa copre questo quiz

  • p + n moves by n elements, not n bytes
  • *(p + 1) vs *p + 1
  • *p++ vs (*p)++
  • Subtracting pointers into the same array
  • The one-past-the-end pointer and what is not allowed

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.