ควิซ C: Function Pointers

This C quiz is about pointers to functions, the tool behind callbacks, qsort comparators and dispatch tables. It checks how they are declared, called and passed around, and the comparator bugs that show up in interviews.

ยาก 10 ข้อ ~8 นาที ผ่านที่ 80% C17

เลือกโหมด

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

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

ข้อ 1 จาก 10

What does this print?

#include <stdio.h>

int add(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }

int main(void) {
    int (*op)(int, int) = add;
    int r1 = op(2, 3);
    op = mul;
    printf("%d %d\n", r1, op(2, 3));
    return 0;
}
ดูเฉลย

C. 5 6 A function name decays to a pointer to the function, so op = add and op = mul just change which function op calls. The first call adds, the second multiplies.

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

  • Declaring int (*op)(int, int) and calling through it
  • Arrays of function pointers as dispatch tables
  • Callbacks and qsort comparators
  • Making declarations readable with typedef
  • int *f(int) vs int (*f)(int)

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

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

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

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

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