Skip to content

Commit 932c097

Browse files
authored
Merge pull request #4457 from science-enthusiast/patch-2
Update const-cpp.md
2 parents b9c4303 + f949c77 commit 932c097

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

docs/cpp/const-cpp.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff 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
153153
const int i = 2;
@@ -159,13 +159,18 @@ You can then use this variable in another module as follows:
159159
extern 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
165165
extern 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
171176
extern "C" const int x=10;

0 commit comments

Comments
 (0)