Why the following example compile with no problems?
#include <iostream>
int main(){
const int var1 = 2;
constexpr int var2 = var1 * 5;
return 0;
}
According to theory: “Variables” that are not constant expressions (their value is not known at compile time)
I used gcc compiler, can be the case that each compiler behave different?
Then how const var1 is known at compile time in this example?
I found other topics about const
vs constexpr
but I still don't understand it.