C++ Primer said if the const can initialize while compile, it will swap the identifier to the value used when initialize, so why I can get the address of a const initialize while compile?
C++ Primer said if the const can initialize while compile, it will swap the identifier to the value used when initialize, so why I can get the address of a const initialize while compile?
The key word in that statement is can. If the compiler can then it may replace your constant with a literal at compile time. If you take the address of the constant then the compiler must allocate memory for it so that there is something to point to. Even if you do this it may still use the literal instead of the memory location when you use the constant in other places.