In this lecture you will learn about the constant expressions in C++.
So C++ 11 introduce a key word called const X for your const expression, const expression, const expert
here.
So this is applied to an expression, and in the case that the expression should be evaluated at a compile
time rather than at runtime.
So for example, let's create an override code here, the const expression double P 1415 and let's create
another const expression, double expression expr double.
And here we're going to write to py.
European.
As you can see, our variable names cannot start with a number here.
So that's why I brought alphabetical to here and two to multiply by pi here.
So this is similar initialization constant declared with the cost keyboard.
However, the cost expert here expression keyboard can also be applied to functions that return a value
that can be evaluated at the compile time.
And so this allows the compiler to optimize the code.
So I want to write another example here.
Let's.
Where I can triangle function here.
Here.
Close to expiration.
So as you can see, this keyboard can be used in functions here and integer.
This takes integer as parameter.
Lets return E equals.
If E equals zero here, you will learn about this later.
What is this?
Just write it and in next lecture you will learn the return statements and what these are in next lecture.
So don't worry, You will learn about all of them here and the key here.
So in this example, the function triangle triangle try inch.
You'll calculate triangular numbers recursively.
So the code uses the conditional operator here.
So in this parenthesis, the function parameter is tested to see if it is a zero here, if it is zero
and if so, the function returns zero.
In fact, ending the reclusion and returning the function to the original color.
So if the parameter is not zero here, then the return value is the sum of the parameter.
And the return value of trying count with the parameter is decrement by one, as you can see here.
So this function when called with a literal in your code can be evaluated at the compile time.
So the cost expert here is an indication to the compiler to check the usage of the function to see if
it can determine the parameter at the compile time.
So if this is the case, the compiler can evaluate the return value and produce more offense efficiency
than by calling the function at runtime.
So if the compiler cannot determine the parameter at the compile time, the function then the called
as just the normal.
So a function marked with the cost x per here keyword must only have one expression and the use of the
conditional operator here as you can see here in the trunk function.