#include #include typedef enum op { ADD, SUB, MUL, DIV, } op; struct operation { int a, b; op o; int (*funcs[2][2])(int, int); }; int add(int a, int b) { return a + b; } int sub(int a, int b) { return a - b; } int mul(int a, int b) { return a * b; } int Div(int a, int b) { return a / b; } int runop(struct operation *o) { switch (o->o) { case ADD: return o->funcs[0][0](o->a, o->b); case SUB: return o->funcs[0][1](o->a, o->b); case MUL: return o->funcs[1][0](o->a, o->b); case DIV: return o->funcs[1][1](o->a, o->b); } return -1; } struct operation *initop(int a, int b, op ope) { struct operation *o = malloc(sizeof(struct operation)); o->a = a; o->b = b; o->funcs[0][0] = &add; o->funcs[0][1] = ⊂ o->funcs[1][0] = &mul; o->funcs[1][1] = &Div; o->o = ope; } int main() { struct operation *o = initop(5, 5, MUL); printf("%d\n", runop(o)); }