Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
int f1 (int x, int y) {
return x + y;
}
int f2 (int x, int y) {
return x - y;
}
typedef int (*binaryOp)(int, int);
void main() {
binaryOp doWork = NULL;
char c;
printf("Please enter 1 or 2");
scanf("%c", &c);
if (c == '1') {
doWork = f1;
} else {
doWork = f2;
}
printf("\nResult = %d", doWork(5, 5));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment