回答編集履歴
2
追記
test
CHANGED
@@ -71,3 +71,37 @@
|
|
71
71
|
}
|
72
72
|
|
73
73
|
```
|
74
|
+
|
75
|
+
[追記-2] いっそコレ↓でよくね?
|
76
|
+
|
77
|
+
```C++
|
78
|
+
|
79
|
+
#include <cstdio>
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
int main() {
|
84
|
+
|
85
|
+
double pcs[2][5]{ 0, 1, 2, 3, 4,
|
86
|
+
|
87
|
+
5, 6, 7, 8, 9 };
|
88
|
+
|
89
|
+
double* PC;
|
90
|
+
|
91
|
+
int N = 0;
|
92
|
+
|
93
|
+
if (N == 1) {
|
94
|
+
|
95
|
+
PC = pcs[0];
|
96
|
+
|
97
|
+
} else {
|
98
|
+
|
99
|
+
PC = pcs[1];
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
printf("\n PC[1]=%7.3f\n", PC[1]);
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
```
|
1
追記
test
CHANGED
@@ -33,3 +33,41 @@
|
|
33
33
|
double pc[5] は {} の外に出ると寿命が尽きてしまいます。
|
34
34
|
|
35
35
|
死んでしまう変数のポインタ値をアテにしてはいかんのです。
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
[追記] これ↓ならOK (staticなのがミソ)
|
40
|
+
|
41
|
+
```C++
|
42
|
+
|
43
|
+
#include <cstdio>
|
44
|
+
|
45
|
+
#include <cstdlib>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
int main() {
|
50
|
+
|
51
|
+
double* PC;
|
52
|
+
|
53
|
+
int N = 1;
|
54
|
+
|
55
|
+
if (N == 1) {
|
56
|
+
|
57
|
+
static double pc[5]{ 1, 0.885, 0.826, 0.794, 0.775 };
|
58
|
+
|
59
|
+
PC = pc;
|
60
|
+
|
61
|
+
} else {
|
62
|
+
|
63
|
+
static double pc[5]{ 1, 0.588, 0.826, 0.794, 0.775 };
|
64
|
+
|
65
|
+
PC = pc;
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
printf("\n PC[1]=%7.3f\n", PC[1]);
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
```
|