const Behaviour in C and C++
In C, the const qualified identifiers will have external linkage, where as in C++ it will have internal linkage. For example,
In C++, the following statement
is implicitly defined as
i.e. the scope of interest_rate is limited to the block in which it is defined.
In C, the above statement will have external linkage when defined at file scope, i.e. it will be visible outside the current translation unit (source file).
The internal linkage of const qualified variables have some advantages in C++. We will cover them in next article.
Thanks to Venki for writing the above fact. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- GFact 22 | (2^x + 1 and Prime)
- GFact 23 | (Brocard’s problem)
- Can C++ reference member be declared without being initialized with declaration?
- Facts and Question related to Style of writing programs in C/C++
- Storage of integer and character values in C
- Vantieghems Theorem for Primality Test
- Cauchy's Mean Value Theorem
- Nesbitt's Inequality
- G-Fact 21 | Collatz Sequence
- G-Fact 20 (Cayley's formula for Number of Labelled Trees)
- G-Fact 19 (Logical and Bitwise Not Operators on Boolean)
- G-Fact 18 | Finding nth Fibonacci Number using Golden Ratio
- fseek() vs rewind() in C
- G-Fact 10
- G-Fact 9