In some cases you will want to provide constant values that can be used throughout your code.
For example, you may decide to declare a constant for P.
You shall not allow this value to be changed because it will change the underlying logic code.
So this means that you should mark the variable as being constant.
So when you do this, the compiler will check the use of the variable and if it is used in the code,
that changes the value of the variable.
The compiler will usually an error.
So let's create a constant variable here.
Constant double.
Yes.
3.14 and 15.
And then double radius.
Double radius equals 5.0.
He has signed a 5.0 and double circumvents.
And to multiply VIP android is here.
So in this case the symbol P here is declared as being constant.
So it cannot change if you subsequently decide to change the constant.
The compiler will usually an error.
So once you declare the constant, you can assure that the compiler will make sure it remains true.
So you can assign the constant with expression as well.
So for example, let's include include C might include k, C, math, C math error, and then let's
make a constant.
Double.
Of two equals.
Constant double score of two equals, STB, score T and two here.
So now I want to change.
For example, as you can see, this is the constant.
We cannot change it, but let's try if we can change our constant value.
So let's assign P to, for example, 99.
As you can see, we got an error cannot assign to variable P with the course qualified type constable.
So in order to work this code, we can as you can see here const we have to delete the cost and now
we can assign P on some variable here.
So let's run our code and see what error we will get.
Error assignment of read only variable p.
As you can see here, we got an error in 12 line P 99.
Here.
So.
Now, as I can show you.
Or we can delete this.
Clear this and with the latest line of code as well.
So in this code, as you can see, we got a constant we created a new double constant skirt of two and
we use the this seam at.
The library, which you will learn more next lectures.
So you can also use constant to declare a constant that will be used as a constant expression for.
So for example, you can declare an array using the square breaks Brexit syntax.
For example, let's create an array here.
Integer values.
Five This is an array, so this declares an array of five integers and the stack and its items are accessed
through the values of a variable.
So the five is here is constant expression.
So when you declare an array on the stack, you have to provide the compiler with a constant expression
so it knows how much memory to allocate.
And this means that the size of the array must be known at compile time so you can allocate an array
with this size known only at runtime.
But this requires dynamic memory allocation, which we will explain in next lecture.
Lex The sections in section named working with memory pointers and arrays.
So in C++ you can declare the constant like this too.
For example, constant integer size equals five integer my new values and pass this as parameter size
here.
So we pass this size.
And as you can see, we all size equals to five.
So these and this line of code is the same, just a different variable names.
So elsewhere in your code, when you access the values array, you can use the size constant to make
sure that you do not don't access items past end of the day, so synthesised variable is declared in
just one place.
You will need to change the size of the array at the later stage, so you have just one place to make
this change.
Also, the keyword here can also be used two pointers and references which you will learn in the next
sections and also on the objects.
Often you will see used on the parameters to functions.
So this is used to get the compiler to help ensure that pointers, references and objects are used appropriately
as you intended.