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()
147147
148148## C and C++ `const` differences
149149
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:
151151
152152```C
153153const int i = 2;
@@ -159,13 +159,18 @@ You can then use this variable in another module as follows:
159159extern const int i;
160160```
161161
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:
163163
164164``` cpp
165165extern const int i = 2 ;
166166```
167+ Similar to C, you can then use this variable in another module as follows:
167168
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:
169174
170175``` cpp
171176extern "C" const int x=10;
You can’t perform that action at this time.
0 commit comments