File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -147,7 +147,7 @@ int main()
147
147
148
148
## C and C++ `const` differences
149
149
150
- When you declare a variable as **`const`** in a C source code file, you do so as:
150
+ When you define a **`const`** variable in a C source code file, you do so as:
151
151
152
152
```C
153
153
const int i = 2;
@@ -159,13 +159,18 @@ You can then use this variable in another module as follows:
159
159
extern const int i;
160
160
```
161
161
162
- But to get the same behavior in C++, you must declare your ** ` const ` ** variable as:
162
+ But to get the same behavior in C++, you must define your ** ` const ` ** variable as:
163
163
164
164
``` cpp
165
165
extern const int i = 2 ;
166
166
```
167
+ Similar to C, you can then use this variable in another module as follows:
167
168
168
- If you wish to declare an ** ` extern ` ** variable in a C++ source code file for use in a C source code file, use:
169
+ ``` cpp
170
+ extern const int i;
171
+ ```
172
+
173
+ If you wish to define an ** ` extern ` ** variable in a C++ source code file for use in a C source code file, use:
169
174
170
175
``` cpp
171
176
extern "C" const int x=10;
You can’t perform that action at this time.
0 commit comments