The const in C is a run-time const that is only defined at compile time and is initialized only at run time, which is why Const cannot be used to define an array, and the value of const can be dynamically modified.
Const in C + + is compile-time const, so it can be used to initialize the array, the value of the attempt to modify the const is undefined, if you want to modify the value of const can only change the const variable is declared as
Const volatile c=10.
Test Case:
const int ci=10;
int *j = (int *) &ci;
*j=100;
printf ("%d,%d", ci,*j);
cout<< "Address I:" <<&ci<<endl;
cout<< "Address J:" <<j<<endl;
The volatile modifier is capable of changing the value of const in C + + because volatile prevents the compiler's constant folding optimization (constant folding optimization: A const variable, or constant), placed in the compiler's symbol table, which is evaluated directly from the table. It eliminates the time it takes to access the memory, thus achieving optimization. And on this basis add the volatile modifier, that is, tell the compiler that the variable is volatile, do not optimize the sentence, each time the calculation to go to the memory to take the number of
Modification of A/C + + const variable