转自:http://www.iteye.com/problems/24480
#include <stdio.h>
#define NULL 0
#define ASGN 1
#define MUL 2
int asgn(int* a, int b) {
return *a = b;
}
int mul(int* a, int b) {
return *a * b;
}
int (*func(int op))(int*, int) {
switch (op) {
case ASGN:
return &asgn;
case MUL:
return &mul;
}
return NULL;
}
int main() {
int i = 0xFEED, j = 0xBEEF;
printf("%x\n", func(ASGN)(&i, j)); // beef
printf("%x\n", func(MUL)(&i, j)); // 8e67a321
printf("%x, %x\n", i, j); // beef, beef
return 0;
}