回答編集履歴
5
変更
answer
CHANGED
@@ -3,8 +3,6 @@
|
|
3
3
|
```c
|
4
4
|
#include <stdio.h>
|
5
5
|
|
6
|
-
typedef int (*FUNCPTR)(int a);
|
7
|
-
|
8
6
|
int call1(int a) { return(a+10); }
|
9
7
|
int call2(int a) { return(a+20); }
|
10
8
|
int call3(int a) { return(a+30); }
|
@@ -12,11 +10,11 @@
|
|
12
10
|
|
13
11
|
void main()
|
14
12
|
{
|
15
|
-
|
13
|
+
int (*po[])() = { call1, call2, call3, call4 };
|
16
14
|
|
17
15
|
int i;
|
18
16
|
for (i=0;i<4;i++){
|
19
|
-
printf("Call Func call%d\n",(
|
17
|
+
printf("Call Func call%d\n",(*po[i])(i));
|
20
18
|
}
|
21
19
|
}
|
22
20
|
```
|
4
変更
answer
CHANGED
@@ -12,11 +12,7 @@
|
|
12
12
|
|
13
13
|
void main()
|
14
14
|
{
|
15
|
-
FUNCPTR tFuncPtr[4];
|
16
|
-
tFuncPtr[
|
15
|
+
FUNCPTR tFuncPtr[4]={&call1, &call2, &call3, &call4};
|
17
|
-
tFuncPtr[1]=&call2;
|
18
|
-
tFuncPtr[2]=&call3;
|
19
|
-
tFuncPtr[3]=&call4;
|
20
16
|
|
21
17
|
int i;
|
22
18
|
for (i=0;i<4;i++){
|
3
変更
answer
CHANGED
@@ -5,32 +5,22 @@
|
|
5
5
|
|
6
6
|
typedef int (*FUNCPTR)(int a);
|
7
7
|
|
8
|
-
int call1(int a) { return(a); }
|
8
|
+
int call1(int a) { return(a+10); }
|
9
|
-
int call2(int a) { return(a); }
|
9
|
+
int call2(int a) { return(a+20); }
|
10
|
-
int call3(int a) { return(a); }
|
10
|
+
int call3(int a) { return(a+30); }
|
11
|
-
int call4(int a) { return(a); }
|
11
|
+
int call4(int a) { return(a+40); }
|
12
12
|
|
13
13
|
void main()
|
14
14
|
{
|
15
|
-
FUNCPTR tFuncPtr;
|
15
|
+
FUNCPTR tFuncPtr[4];
|
16
|
+
tFuncPtr[0]=&call1;
|
17
|
+
tFuncPtr[1]=&call2;
|
18
|
+
tFuncPtr[2]=&call3;
|
19
|
+
tFuncPtr[3]=&call4;
|
16
20
|
|
17
21
|
int i;
|
18
|
-
for (i=
|
22
|
+
for (i=0;i<4;i++){
|
19
|
-
switch(i){
|
20
|
-
case 1:
|
21
|
-
tFuncPtr=&call1;
|
22
|
-
break;
|
23
|
-
case 2:
|
24
|
-
tFuncPtr=&call2;
|
25
|
-
break;
|
26
|
-
case 3:
|
27
|
-
tFuncPtr=&call3;
|
28
|
-
break;
|
29
|
-
case 4:
|
30
|
-
tFuncPtr=&call4;
|
31
|
-
break;
|
32
|
-
}
|
33
|
-
printf("Call Func call%d\n",(tFuncPtr)(i));
|
23
|
+
printf("Call Func call%d\n",(tFuncPtr[i])(i));
|
34
24
|
}
|
35
25
|
}
|
36
26
|
```
|
2
変更
answer
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
c言語で書いてみました。
|
1
|
+
c言語で書いてみました。綺麗とは言えませんが。
|
2
2
|
|
3
3
|
```c
|
4
4
|
#include <stdio.h>
|
1
変更
answer
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
c言語で書いてみました。
|
1
|
+
c言語で書いてみました。華麗ではありませんが。
|
2
2
|
|
3
3
|
```c
|
4
4
|
#include <stdio.h>
|