- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayFunctionPointer.c
More file actions
Latest commit
35 lines (26 loc) · 672 Bytes
/
Copy pathArrayFunctionPointer.c
File metadata and controls
35 lines (26 loc) · 672 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<stdio.h>
intadd (intnum1,intnum2){
returnnum1+num2;
}
intsubtract (intnum1, intnum2){
returnnum1-num2;
}
/*int mul(int num1,int num2){
return num1*num2;
}*/
typedefint (*fptrOperation) (int ,int);
fptrOperationoperations[128] = {NULL};
voidinitializeOperationsArray(){
operations['+'] =add;
operations['-'] =subtract;
}
intevaluateArray(charopcode,intnum1,intnum2){
fptrOperationoperation;
operation=operations[opcode];
returnoperation(num1,num2);
}
voidmain(){
initializeOperationsArray();
printf("%d\n",evaluateArray('+',5,6));
printf("%d\n",evaluateArray('-',5,6));
}