We already know that the const variable cannot be modified. C + + also provides a more "strict" constexpr specifier (constexpr-specifier), when a variable is declared or defined, if the type specifier is preceded or followed by a constexpr specifier, Indicates that the variable is a const variable and that the variable must be initialized. The expression used to initialize the variable must be a "constant expression", even more restrictive than const,constexpr. This means that the CONSTEXPR variable is a const variable initialized by a constant expression. For basic data types, a constant expression is an expression consisting of a literal constant, a variable that is constexpr, and a const variable initialized by a constant expression. In other words, the value of a constant expression can be determined during compilation. For example
- int nonconst_var = 100;
- const int const_var1 = 2;
- const INT CONST_VAR2 = NONCONST_VAR;   
- constexpr int constexpr_var1 = 3 + const_var1 * 4; //established
- constexpr int constexpr_var2 = 3 + nonconst_var * 4; //error
- constexpr int Constexpr_var3 = 3 + const_var2 * 4; //error
Const and CONSTEXPR