Today, when I was reading the chapter "constexrp and constant expressions" of CPP Primer, I found this sentence:
A "constant expression is an expression whose value does not change and gets the result of evaluation during compilation
"
there is also:
the new CPP11 standard states that allows variables to be declared as constexpr so that the compiler verifies whether the value of the variable is a constant expression
"
when verifying the constexpr type specifier function, I wrote the following code:
-sharpinclude <iostream>
int a = 99;
constexpr int *pa = &a;
int main()
{
std::cout<<pa<<std::endl;
return 0;
}
this code compiles and outputs the result;
my question is that, as I have always understood, the data in the program is only loaded into memory at run time, where a should be placed in the global / static storage area;
and here constexpr int * pa = & a
passed the compilation, indicating that & a
is a constant expression that can get the result during compilation, so here the CPP compiler gets the result of & a
, that is, the address of a?