Function Execution and Variable Initialization
Learn the differences between const, constexpr, consteval, and constinit in C++20. Understand how these keywords affect function execution at run time or compile time, and how they influence variable initialization for optimized program behavior.
We'll cover the following...
We'll cover the following...
Now it’s time to write about the differences between const, constexpr, consteval, and constinit. First, I discuss function execution and then variable initialization.
Function execution
The following program has three versions of a square function.
As the name suggests: the ordinary function sqrRunTime (line 3) runs at run time, the consteval function ...