-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctionPointers.cpp
More file actions
59 lines (44 loc) · 888 Bytes
/
Copy pathfunctionPointers.cpp
File metadata and controls
59 lines (44 loc) · 888 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
//How to use function as function input using function address and pointers (callback function)
int sum(int a, int b);
int sub(int a, int b);
int mult(int a, int b);
int dive(int a, int b);
int main()
{
int chose;
int number1;
int number2;
int result;
std::cout << "number1=" << std::endl;
std::cin >> number1;
std::cout << "number2=" << std::endl;
std::cin >> number2;
std::cout << "chose=" << std::endl;
std::cin >> chose;
int (*math[4])(int a, int b);
math[0] = sum;
math[1] = sub;
math[2] = mult;
math[3] = dive;
result = math[chose](number1, number2);
std::cout << "result=" << std::endl;
std::cout << result << std::endl;
return 0;
};
int sum(int a, int b)
{
return a + b;
};
int sub(int a, int b)
{
return a - b;
};
int mult(int a, int b)
{
return a * b;
};
int dive(int a, int b)
{
return a / b;
};