In this lecture you will learn about the default values in C++.
So variables of a built in types should we initialize 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 the file scope.
Or global in your project and you don't give it an initial value, the compiler will give it a default
value, for example.
So it'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 our outside.
This is the integer manager integer.
So we will we're going to use the decimal format specified 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 to one so.
The critical 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 zero by default and here incremented increment by one, by
plus one.
Plus one.
And here I'll put here one here.
And let's create another example here which called inside.
So create an inside, inside actual integer.
Inside it's going to be 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 ops, this is the outside, one outside.
And then print the inside one here, print test.
K inside.
Yes.
And your pass inside as an argument here, parameter here and then now.
Let's compile and run our application.
So as you can see, I'm sorry, I have to add the new line here.
We don't have to add to 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 an initialized variable.
So in the last lecture we have another example of the compiler providing the default value static.
So here as let's create an example here, static integer count here, for example, return here, there's
going to be zero 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 or count function whenever we want.
And then let's add here our integer counter function.
Then static.
Let's add the static integer count variable here.
And this counter, as you can see here, this function returns integer.
So we're going to return the integer.
As you can see, count is integer and variable is integer.
So it's in order to more understandable since right like variable type.
So here plus plus count.
We 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 a 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 over 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.
But it will return the value one.
I'm sorry I mistaken.
It will return the value one because the increment is my count by one returns one returns one here.
Actually.
Let's print count.
Function.
From.
Shown here and the counter here past counter.
And let's see what happens.
As you can see here, count function gave a counter function gave us returned as one.
And we have a new initialize list syntax of C++ 11.
So this is the update upgrade on the C++ language here.
So the initialize list syntax of C++ 11 provides a way for you declare a variable and specify that you
want it initialized by the compiler to default value for the type.
So for example, let's create an example variable here integer A here and then like this.
It might be strange, but I will explain all of this.
So of course when you read this code, 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 null here.
So this is the also zero.
I want to mention here and here.
Char default value is our default value is here.
Parenthesis 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.
The point for pointer is pointer for here is the pound value is no Peter, which I will explain what
null TR is.
So in next lecture we're going to learn that declarations with without a type.
So I'm waiting you in next lecture.