回答編集履歴
2
おのれC
test
CHANGED
@@ -75,3 +75,49 @@
|
|
75
75
|
|
76
76
|
|
77
77
|
となり、値は不定じゃないんですね。
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
---
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
あああ、C++に毒されていた。
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
そういえばCはstatic変数とconst修飾されている変数は別として(volatile修飾のときの扱いは忘れた)、変数の定義と同時じゃなくても最初の代入まで初期化という扱いでしたね、ちくせう。
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
```c
|
94
|
+
|
95
|
+
static int n1;//非明示的初期化
|
96
|
+
|
97
|
+
n1 = 2;//代入
|
98
|
+
|
99
|
+
static int n2;//非明示的初期化
|
100
|
+
|
101
|
+
int main(void)
|
102
|
+
|
103
|
+
{
|
104
|
+
|
105
|
+
int a;
|
106
|
+
|
107
|
+
a = 3;//Cだとこれも初期化
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
const int b = 0;//const修飾されているときは定義と同時にしか初期化できない
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
n2 = 3;//代入
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
return 0;
|
120
|
+
|
121
|
+
}
|
122
|
+
|
123
|
+
```
|
1
m
test
CHANGED
@@ -38,13 +38,13 @@
|
|
38
38
|
|
39
39
|
> 10 If an object that has automatic storage duration is not initialized explicitly, its value is
|
40
40
|
|
41
|
-
indeterminate. If an object that has static or thread storage duration is not initialized
|
41
|
+
indeterminate. **If an object that has static or thread storage duration is not initialized
|
42
42
|
|
43
|
-
explicitly, then:
|
43
|
+
explicitly**, then:
|
44
44
|
|
45
45
|
— if it has pointer type, it is initialized to a null pointer;
|
46
46
|
|
47
|
-
— if it has arithmetic type, it is initialized to (positive or unsigned) zero;
|
47
|
+
— **if it has arithmetic type, it is initialized to (positive or unsigned) zero;**
|
48
48
|
|
49
49
|
— if it is an aggregate, every member is initialized (recursively) according to these rules,
|
50
50
|
|