Initial users.
Initially users were touched upon in the last lectures, but we will go into more depth here.
So for built in types, you must initialize a variable before you use it.
So for custom types it is possible for the type to define a default value, but there are some users
in doing this which will be covered in next lecture.
Which in next chapters.
Which in which.
Yeah, in classes chapter of this Oxley Udemy course.
So in all versions of C++, there are three ways to initialize a world in type.
The first here three ways to initialize.
Boiled.
Point in time.
The first is assignment, which I will explain all of this assignment function.
Syntax.
Thanks for calling.
And constructor.
So.
Here.
Now let's try.
Firstly, try with assignment, then function, then syntax and then call a.
Actually it's a four way, so I'm sorry for it.
It's four ways for colleague in slicers.
So still C plus 11.
Another way to initialize variables was introduced construction toward list visualizer.
So there are four types here, as I said.
So let's firstly create our in our codes and writer codes and use for initializes here include standard
steel here just for.
Putting it here So integer.
Actually, we didn't need here.
I just wanted integer.
E here.
Integer g equals integer two which I.
Yeah.
It's it's.
It seems like pretty strange, but I will explain all of this.
Don't worry.
Integer key here.
Actually.
Let's make this e, b c integer C tree or like this tree and then integer M four.
Integer RD four.
So as you can see here, we did we initialized for four variables to four integers.
So the first of these three is the clearest types.
So it shows using an easy to understand syntax that the variable is being initialized to a value.
So the second example here initialize a variable by calling the type as if it is a function.
So as you can see, the second is a function calling it by function.
And the third example calls the constructor of the integer type.
So this is a typical way to initialize custom types, so it's best to reserve the syntax just for custom
types.
So and the fourth here, as you can see here, syntax is new here.
Excel.
Let me write it here.
New, new to C++.
So this is the kind of new to C++.
It actually came with C++ 11 and initialized initializes the variable using an initialized list between
the curly braces here, as you can see here.
And just to confuse things slightly, you can also initialize a built in type using the same syntax
as an assignment to a single to a single item list.
For example, integer E here equals equal to here and five like this.
So you can assign this operator like this too.
So now I want to print these variables just in case to show that these variables works and you can print
this value to screen.
So let's print print f.
Okay here.
Stop.
Decimal.
New line.
Decimal.
New line.
Decimal and new line.
Decimal.
New line.
Lastly, actually, let's add five decimal here.
Excellent.
Same with the set here.
And new variable.
One, two, three, four.
The financial and then the these variables.
He equals.
The calls.
Sea Eagles.
Cruelty.
The cruelty.
And E quality.
Yeah.
And then.
E.
B.
C.
D.
E.
And actually I've got the right mean function and germane here.
And then.
So actually is the line, the writing these things is pretty easy.
So as you can see here, it added one tab between the this last line automatically.
So now let's print our function actually.
Take this vegetables to.
Main main function here.
UPS by the telco.
Take this to main function and compile and run our application.
So as you can see here, we initialize with the first type, assign assignment type and print it to.
Bring it to console.
Here we come online and then we did the function B two, C three, D four.
And these are the same actually with syntax calling, calling a constructor type, which is a kind of
new to C++ language.
And I'm going to show you another thing.
So just initializing the arrays here.
So actually.
Initializing arrays.
Initializing.
Actually, it's print F.
Initializing types of initializing types.
And then.
Have just print print test.
Initialize.
Race and let's create our race.
So this is a really confusing things.
So the type here, the type E here is an integer, but not an array.
So as you know, we can write arrays like this, for example, integer integer, birth year, for example,
birth years, and then, for example.
One.
For example, like this we can with this quarter versus we always did just creating a rate things,
as you can see.
But here we're signing something just one variable to.
Integers.
So this is kind of confusing.
I know.
So just to configure things slightly, you can also initialize a builtin type using the same syntax
here as an assignment to a single item list.
So recall that in the last lecture we created an array with the birthdates and I did this.
I brought this code again.
So this creates an array of four integers.
So the type of each item is an integer, as you can see here.
But the type of the array variable is integer pointer here into the asterisk.
So the variable points to memory that holds for integers.
So similarly you can initialize also initialize a variable to be an array of one of them.
For example, integer John.
And.
For example, John, for example, this rather John's birthday, 1988.
And as you can see here, we did.
Creating just a single array so we can use it as the just usual integer here.
So this is exactly the same initialize initialization code that C++, C++ 11, C++ 11 allows to initialize
a single integer.
In addition, the same syntax is used to initialize instances of record types as you know, structs.
Yeah.
So adding another level of potential confusion about what syntax means.
So it's best to avoid using the curly braces for variable initialization and use it exclusively for
initialization lists.
So just avoid this.
I just, I just want to show you that C++ 11 has this feature.
So however, there are advantages of this syntax for casting as explained shortly.
So the core libraries syntax can use provide the initial values for any of the collection classes in
C++ Standard Library.