#include <stdio.h>
int function_a(int a, int b)
{
printf("Inside function_a: %d %d\n", a
, b
); return a+b;
}
int function_b(int a, int b)
{
printf("Inside function_b: %d %d\n", a
, b
); return a+b;
}
int function_c(int a, int b)
{
printf("Inside function_c: %d %d\n", a
, b
); return a+b;
}
int function_whatever(int a, int b)
{
printf("Inside function_whatever: %d %d\n", a
, b
); return a+b;
}
int (* get_function(char c)) (int, int)
{
switch(c)
{
case 'A':
return function_a;
case 'B':
return function_b;
case 'C':
return function_c;
}
return function_whatever;
}
int main(void) {
get_function('B')(3, 5);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgZnVuY3Rpb25fYShpbnQgYSwgaW50IGIpCnsKCXByaW50ZigiSW5zaWRlIGZ1bmN0aW9uX2E6ICVkICVkXG4iLCBhLCBiKTsKCXJldHVybiBhK2I7Cn0KCmludCBmdW5jdGlvbl9iKGludCBhLCBpbnQgYikKewoJcHJpbnRmKCJJbnNpZGUgZnVuY3Rpb25fYjogJWQgJWRcbiIsIGEsIGIpOwoJcmV0dXJuIGErYjsKfQoKaW50IGZ1bmN0aW9uX2MoaW50IGEsIGludCBiKQp7CglwcmludGYoIkluc2lkZSBmdW5jdGlvbl9jOiAlZCAlZFxuIiwgYSwgYik7CglyZXR1cm4gYStiOwp9CgppbnQgZnVuY3Rpb25fd2hhdGV2ZXIoaW50IGEsIGludCBiKQp7CglwcmludGYoIkluc2lkZSBmdW5jdGlvbl93aGF0ZXZlcjogJWQgJWRcbiIsIGEsIGIpOwoJcmV0dXJuIGErYjsKfQoKCmludCAoKiBnZXRfZnVuY3Rpb24oY2hhciBjKSkgKGludCwgaW50KQp7Cglzd2l0Y2goYykKCXsKCQljYXNlICdBJzoKCQkJcmV0dXJuIGZ1bmN0aW9uX2E7CgkJY2FzZSAnQic6CgkJCXJldHVybiBmdW5jdGlvbl9iOwoJCWNhc2UgJ0MnOgoJCQlyZXR1cm4gZnVuY3Rpb25fYzsKCX0KCXJldHVybiBmdW5jdGlvbl93aGF0ZXZlcjsKfQoKaW50IG1haW4odm9pZCkgewoJZ2V0X2Z1bmN0aW9uKCdCJykoMywgNSk7CglyZXR1cm4gMDsKfQo=