-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_pointer.c
More file actions
46 lines (38 loc) · 913 Bytes
/
Copy pathfunction_pointer.c
File metadata and controls
46 lines (38 loc) · 913 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
#include <stdio.h>
// int tambah(int x, int y) {
// return x + y;
// }
//
// int kurang (int x, int y) {
// return x - y;
// }
//
// int kali (int x, int y) {
// return x * y;
// }
// void pilih_operasi(int(*operasi)(int, int), int x, int y) {
// int hasil = operasi(x, y);
// printf("hasil operasi adalah : %d\n", hasil);
// }
//
void proses_data(int (*callback)(int)) {
int data[] = {1,2,3,4,5,6,7,8,9,10};
for (int i = 0; i < 10; i++) {
printf("%d ", callback(data[i]));
}
printf("\n");
}
int kuadrat(int x){
return x * x;
}
int main() {
proses_data(kuadrat);
// int (*operasi)(int, int);
// operasi = &tambah;
// pilih_operasi(tambah, 50, 30);
// // printf("hasil tambah adalah %d\n", operasi(10, 20));v
// int (*operasi[3]) (int, int) = {tambah, kali, kurang};
// int a = 10; int b = 20;
// printf("hasil operasi adalah %d\n", operasi[1](a, b));
return 0;
}