you have a cpp source already, what's the exact question?
#include <stdio.h> int Add(int a, int b) { return a + b; } int Mul(int a, int b) { return a * b; } int main() { int (*ptr_add)(int, int) = Add; // Declare directly typedef int (*BinaryFn)(int, int); // Or use the human-friendlier way BinaryFn ptr_mul = &Mul; // Bonus question: are `&Mul` and `Mul` interchangeable? // Bonus question: are `(*ptr_mul)` and `ptr_mul` interchangeable? printf("2 + 3 * 4 = %d\n", ptr_add(2, (*ptr_mul)(3, 4))); return 0; } // Bonus question besides homework assignment: how to interpret the following // function appeared in signal(3): // void (*signal(int sig, void (*func)(int)))(int); // // Hint: see signal(2)
Обсуждают сегодня