Home > Back-end >  C const modified constant problems
C const modified constant problems

Time:10-05

This c + + code, address in VS2014 output, but the value is different! Rookie, I don't know the reason, want to consult everybody Daniel how to explain:

const int arrSize=10;

cout <& lt;" ArrSize="& lt; 10 Addr arrSize==00 c3f808
10 Addr arrSize==00 c3f808
* 11 Addr parrSize==00 c3f808

Clearly address is the same, why itself value is different? Has been under the Debug and Release test is,

There are two question consult everybody, check a lot of information, some said const definition of built-in type, do not need to allocate memory (it wasn't quite right. After all, can address?) , some say as long as a allocated memory, no longer in the subsequent use allocation (individual feels more solid), and, in the compile phase defined in the symbol table, this variable is not included in the real exe (not understand), is there any authority point, exactly what kind of situation? Second, the compiler is not a modification of how to realize the const? Just to check whether the assignment operation is in the code to judge illegal? Or like macros defined as constants to replace directly? Thank you very much!
  • Related