- Esecutori
-
Impara
Impara Python Esempi eseguibili, NumPy, pandas e altro Impara l'IA / Machine LearningReti neurali, ML e LLM da zero Impara C e C++ Puntatori, memoria, STL e C++ moderno Impara C#Fondamenti, OOP, LINQ, async ed esercizi .NET Impara MatplotlibGrafici a linee, barre, dispersione e torta con visualizzatori Impara RustOwnership, trait, gestione degli errori e thread Impara GoSlice, interfacce, goroutine e canali Algoritmi Python Ricerca, ordinamento, ricorsione e visualizzazioni O(n) Algoritmi C e C++ Confronta le implementazioni in C e C++ Programmazione per bambini Impara a programmare giocando!
- QuizNuovo
- SfideNuovo
- Per docentiNuovo
- Aggiornamenti
- Offrimi un caffè
Quiz di 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.
Domanda di esempio
Domanda 1 di 10What 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;
}
Mostra la risposta
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.
Cosa copre questo quiz
- Declaring
int (*op)(int, int)and calling through it - Arrays of function pointers as dispatch tables
- Callbacks and
qsortcomparators - Making declarations readable with
typedef int *f(int)vsint (*f)(int)
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.