回答編集履歴
5
変更
test
CHANGED
@@ -5,10 +5,6 @@
|
|
5
5
|
```c
|
6
6
|
|
7
7
|
#include <stdio.h>
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
typedef int (*FUNCPTR)(int a);
|
12
8
|
|
13
9
|
|
14
10
|
|
@@ -26,7 +22,7 @@
|
|
26
22
|
|
27
23
|
{
|
28
24
|
|
29
|
-
|
25
|
+
int (*po[])() = { call1, call2, call3, call4 };
|
30
26
|
|
31
27
|
|
32
28
|
|
@@ -34,7 +30,7 @@
|
|
34
30
|
|
35
31
|
for (i=0;i<4;i++){
|
36
32
|
|
37
|
-
printf("Call Func call%d\n",(
|
33
|
+
printf("Call Func call%d\n",(*po[i])(i));
|
38
34
|
|
39
35
|
}
|
40
36
|
|
4
変更
test
CHANGED
@@ -26,15 +26,7 @@
|
|
26
26
|
|
27
27
|
{
|
28
28
|
|
29
|
-
FUNCPTR tFuncPtr[4];
|
30
|
-
|
31
|
-
tFuncPtr[
|
29
|
+
FUNCPTR tFuncPtr[4]={&call1, &call2, &call3, &call4};
|
32
|
-
|
33
|
-
tFuncPtr[1]=&call2;
|
34
|
-
|
35
|
-
tFuncPtr[2]=&call3;
|
36
|
-
|
37
|
-
tFuncPtr[3]=&call4;
|
38
30
|
|
39
31
|
|
40
32
|
|
3
変更
test
CHANGED
@@ -12,13 +12,13 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
-
int call1(int a) { return(a); }
|
15
|
+
int call1(int a) { return(a+10); }
|
16
16
|
|
17
|
-
int call2(int a) { return(a); }
|
17
|
+
int call2(int a) { return(a+20); }
|
18
18
|
|
19
|
-
int call3(int a) { return(a); }
|
19
|
+
int call3(int a) { return(a+30); }
|
20
20
|
|
21
|
-
int call4(int a) { return(a); }
|
21
|
+
int call4(int a) { return(a+40); }
|
22
22
|
|
23
23
|
|
24
24
|
|
@@ -26,43 +26,23 @@
|
|
26
26
|
|
27
27
|
{
|
28
28
|
|
29
|
-
FUNCPTR tFuncPtr;
|
29
|
+
FUNCPTR tFuncPtr[4];
|
30
|
+
|
31
|
+
tFuncPtr[0]=&call1;
|
32
|
+
|
33
|
+
tFuncPtr[1]=&call2;
|
34
|
+
|
35
|
+
tFuncPtr[2]=&call3;
|
36
|
+
|
37
|
+
tFuncPtr[3]=&call4;
|
30
38
|
|
31
39
|
|
32
40
|
|
33
41
|
int i;
|
34
42
|
|
35
|
-
for (i=
|
43
|
+
for (i=0;i<4;i++){
|
36
44
|
|
37
|
-
switch(i){
|
38
|
-
|
39
|
-
case 1:
|
40
|
-
|
41
|
-
tFuncPtr=&call1;
|
42
|
-
|
43
|
-
break;
|
44
|
-
|
45
|
-
case 2:
|
46
|
-
|
47
|
-
tFuncPtr=&call2;
|
48
|
-
|
49
|
-
break;
|
50
|
-
|
51
|
-
case 3:
|
52
|
-
|
53
|
-
tFuncPtr=&call3;
|
54
|
-
|
55
|
-
break;
|
56
|
-
|
57
|
-
case 4:
|
58
|
-
|
59
|
-
tFuncPtr=&call4;
|
60
|
-
|
61
|
-
break;
|
62
|
-
|
63
|
-
}
|
64
|
-
|
65
|
-
printf("Call Func call%d\n",(tFuncPtr)(i));
|
45
|
+
printf("Call Func call%d\n",(tFuncPtr[i])(i));
|
66
46
|
|
67
47
|
}
|
68
48
|
|
2
変更
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
c言語で書いてみました。
|
1
|
+
c言語で書いてみました。綺麗とは言えませんが。
|
2
2
|
|
3
3
|
|
4
4
|
|
1
変更
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
c言語で書いてみました。
|
1
|
+
c言語で書いてみました。華麗ではありませんが。
|
2
2
|
|
3
3
|
|
4
4
|
|