Can CPP get the address of the variable during compilation?

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?

.
CPP
Mar.28,2022

has not used CPP, but the compiler will determine the address of the variable
during the compilation process, while the local variable is different. It is the address on the stack that is determined on the run
for example:
if I compile a language and allocate a block of memory in memory for variables to use, suppose the address starts at 0 and encounters a new variable whose address is marked as 0 and recorded in the hash. A new variable is encountered in the table with the address marked 1, and so on, and recorded in a symbol table. If a variable encountered is already in the hash table, it means it is not a new variable

.
//  
{
    a: 0,
    b: 1,
    c: 2
}

your understanding is correct. This is the characteristic of global variables.
an error will be reported if it is placed inside the main function

prog.cc: In function 'int main()':
prog.cc:9:21: error: '& a' is not a constant expression
    9 | constexpr int *pa = &a;
      |  

this a has an address at compile time, which is the relative address. After the link or executable file is loaded into memory, it will be relocated and changed. The data in


C/CPP is loaded into memory at run time, but the location where the data is stored, that is, the address (the offset of the address, to be exact) is determined at compile time. So & an is a compile-time constant.


compiled programs do not have variable names and are accessed through different addressing rules. Net is special. I now talk about how c handles it. If it is a static variable in a function, the global variable program is accessed directly with a fixed address, that is to say, if it is written in the code & a, the code to obtain the address of the variable a does not require any extra calculation. Because the program only knows the address of a from the beginning (if you want to access the value of a, you need to calculate extra)


very roughly speaking, all you know at compile time is the address in the executable file. The memory at execution time is mapped by an executable file.


compiled programs have no variable names

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c770-2c2f8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c770-2c2f8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?