update of example
@@ -0,0 +1,29 @@ | ||
1 | +#include <stdio.h> | |
2 | +#include <stdlib.h> | |
3 | +typedef int (*func) (); | |
4 | + | |
5 | +int main() | |
6 | +{ | |
7 | + int inc(const int n) { | |
8 | + { | |
9 | + return n + 1; | |
10 | + } | |
11 | + } | |
12 | + int dec(const int n) { | |
13 | + { | |
14 | + return n - 1; | |
15 | + } | |
16 | + } | |
17 | + int calc(const func f, const int n) { | |
18 | + { | |
19 | + return (*f) (n); | |
20 | + } | |
21 | + } | |
22 | + { | |
23 | + const int a = calc(inc, 1); | |
24 | + const int b = calc(dec, 1); | |
25 | + printf("%d ", a); | |
26 | + printf("%d ", b); | |
27 | + printf("\n"); | |
28 | + } | |
29 | +} |