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

Mittel 10 Fragen ~6 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 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;
}
Lösung zeigen

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.

Darum geht es in diesem 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

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.