-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
68 lines (54 loc) · 1.21 KB
/
main.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* 30.03.2021
Function pointers*/
#include <stdio.h>
int add_func( int x , int y) {
printf("add_func = x + y = %d\n" , x + y );
return x + y;
}
int sub_func(int x, int y) {
printf("sub_func = x - y = %d\n", x - y);
return x - y;
}
int mul_func(int x, int y) {
printf("mul_func = x * y = %d\n", x * y);
return x * y;
}
int div_func(int x, int y) {
printf("div_func = x / y = %d\n", x / y);
return x / y;
}
int main()
{
int (*pFuncs[5])(int, int);
pFuncs[0] = add_func;
pFuncs[1] = sub_func;
pFuncs[2] = mul_func;
pFuncs[3] = div_func;
pFuncs[4] = NULL;
//opcode
int cmd[10] = { 2 , 0 , 3 , 1 , 2 , 2 , -1 };
int t1, t2;
t1 = 70;
t2 = 8;
int n = 0;
while (cmd[n] != -1) {
/* Klasik Ardisik if denetimi*/
/*
if (cmd[n] == 0)
add_func(t1, t2);
else
if (cmd[n] == 1)
sub_func(t1, t2);
else
if (cmd[n] == 2)
mul_func(t1, t2);
else
if (cmd[n] == 3)
div_func(t1, t2);
*/
/*Fonksiyon Pointeri ile çalışma Şekli*/
pFuncs[cmd[n]]( t1, t2 );
n++;
}
return 0;
}