What is the difference between constexpr and creating a variable?

The value is evaluated at compile time. What you’re talking about is static typing. For an example of constexpr I have used Compile Explorer which shows you the generated assembly on the right. The following is with GCC 6.3 and with no optimisations.

No constexpr:


constexpr:

Now the general principle of assembly, lesss is better. Though here you can see that in the constexpr version the function and function call (lines 1-8 +14) have disappeared and replaced with line 4

Edit: made code simpler.