In this lecture you will learn about the default values in C plus plus.
So variables of a built in types should be initialized before you first use them.
But there are some situations when the compiler will provide a default value.
So if you declare a variable at a file scope.
Uh, or globally in your project and you don't give it an initial value, the compiler will give it
a default value, for example.
So let's outside create an outside variable.
Integer outside and then create an inside variable, for example.
Or let's increment outside by one and then print f our outside.
This is the integer manager integer.
So we will we're going to use the decimal format specifier here and then pass our outside as an argument
and let's compile our application and see what happens.
As you can see here, we got the one.
So.
The code will compile and run and it printed the value one so the compiler has initialized the outside
to zero.
So when it's incremented to one.
So actually, let me write this here outside um, zero by default and here incremented increment by
one.
Uh, by plus one.
Plus one.
And here, um, output here, one here.
And let's create another example here, which called inside.
So create an inside, inside actually integer inside.
It's going to be an integer type inside and do not assign anything on it.
And let's increment inside by one plus plus here and let's print the inside variable.
Actually, let's mention here inside of this is an outside one outside and then print the inside one
here.
Print f, okay.
Inside.
Yes.
And here pass insight as an argument here.
Parameter here and then.
Let's compile and run our application.
So as you can.
I'm sorry.
I have to add the new line here.
We don't have to add to the last line, but it's okay.
So let's add it just in case.
As you can see, inside, one outside one.
So.
And here the compiler will compile and the increment operator is being used as a uninitialized variable.
So in the last lecture we have another example of the compiler providing the default value static.
So here, let's create an example here.
Um, static integer count here, for example, return.
Uh, here we're just going to be here.
Return plus plus, count here count.
So as you can see here, actually it's let's instead of writing like this, let's create another count
function so we don't mess with the main function here and call our count function whenever we want.
And then let's add here our integer count function.
Uh, then static.
Let's add the static integer count variable here.
And this counter, as you can see here, this function returns an integer.
So we're going to return the integer.
As you can see, count is integer, count variable is integer.
So it's in order to more understandable.
So let's like write like variable type.
So here, plus plus count.
You will see.
Actually, my count.
Plus.
Plus my count.
My count.
So this is a simple function that maintains a count.
So the variable count here, my count is marked with the static search class modifier, meaning that
the variable has the same lifetime as the application so located when?
So this allocated when the code starts and they are located when the program ends.
So however it has an internal linkage.
So meaning the variable can only be used within the scope of where it is declared.
So the counter function.
So the compiler will initialize the count my count variable with a default value of zero.
And then so that the first time counter function is called, it will return the value zero.
So, so, so.
But it will return the value one.
I'm sorry, I'm mistaken.
It will return the value one because we increment it.
This my count by one returns one returns one here.
Okay.
Actually, let's print death count.
Function.
From.
Shown here and the, uh, counter here, uh, past counter and let's see what happens.
As you can see here, count function gave counter function gave us, returned us one.
And we have a new initializer list, syntax of C plus plus 11.
So this is the update upgrade on C plus plus language here.
So the initial initializer list, syntax of C plus plus 11 provides a way for you.
Declare a variable and specify that you want it initialized by the compiler to the default value for
the type.
So for example, let's create an example variable here, integer A here and then like this.
So it might be strange, but I will explain all of this.
So of course when you read this code, it's you have to know that the default value for an integer is
zero.
So again, it's much easier, easier and more explicit to simply initialize the variable to a value.
E equals equals zero.
Here, of course it's more easy, but the rules for the default values are simple.
A value of zero.
So integers and floating point numbers have a default value of zero for a character.
The default value is.
Let me show here like this.
This is the zero.
So for a bool is false and for a pointer is the constant nullptr here.
So this is the also zero.
I want to here mention here and here.
Char default value is our default value is here.
Parentheses slash zero boolean bool default value is false and the floating point number is same as
the integer.
It is zero.
And let me mention it for pointer.
It's a pointer.
Pointer is default, value is nullptr, which I will explain what nullptr is.
So in next lecture we're going to learn the declarations with without a type.
So I'm waiting you in next lecture.