ควิซ 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.

ปานกลาง 10 ข้อ ~6 นาที ผ่านที่ 80% C17

เลือกโหมด

กำลังเล่นแบบผู้เยี่ยมชม: เข้าสู่ระบบเพื่อเก็บ XP และ streak

ตัวอย่างคำถาม

ข้อ 1 จาก 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;
}
ดูเฉลย

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.

ควิซนี้มีเนื้อหาอะไรบ้าง

  • 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

คำถามที่พบบ่อย

ต้องมีบัญชีไหม?

ไม่ต้อง ใครก็เล่นได้ เข้าสู่ระบบเพื่อเก็บ XP, streak, เหรียญตรา และประวัติ

ทำซ้ำได้ไหม?

ได้ ระบบเก็บคะแนนที่ดีที่สุดไว้ และสลับคำถามกับตัวเลือกใหม่ทุกครั้ง