Hey, guys, what's up?
So our today's topic is typecasting.
It is a very easy topic.
So typecasting means cast wonder your type two other did a type that means convert one did a type to
other, did a type.
So typecasting is of two types.
Implicit.
In blizzard typecasting and explicit typecasting.
So first of all, we were allowed implicit typecasting.
So let's make a new file.
Compiling an.
OK, so let's Neamat.
Typecasting.
Not the CPB.
OK, so first of all, we are talking about implicit typecasting.
So tell me what really my output, if I do see out two plus three.
Obviously my output will be five.
No issue.
But if I do.
Ghazi GWAS character a and then I ride see old.
C plus.
Let's make it a C out, a plus three.
What do you mean output?
Let's send it.
So my output is coming out to be handed way.
So what happened is this Pless operator is defined for numbers and is not defined for characters.
So what this plus operator is doing, it is converting a 2D archiving loop, which is 97.
And then it is adding through to it.
So 97 plus three comes out to be handed.
Okay, so this is called typecasting.
This character has been converted into 97.
Okay, so we have not type gustad.
It is done automatically by the compiler.
That's why it is called implicit.
Implicit means automatically type conversion.
It is done by compiler, not by us.
Okay, so let's see some more example of implicit typecasting.
So instead of character here, we can also ride.
See, because Variable C contains character only.
Now, if I had, I'd see out characters, see so many variables, see multiplied three.
What will happen?
Come on, get out.
Now let's bail an.
So 291 is my output.
So what is happening here?
This.
Just a second.
So this.
Multiplication operator is also defined for numbers.
It does not define folk characters.
So it is typecasting.
It is converting variable C, which is holding correct that A. into its skyway is ninety 97 and 97 multiplied
by three is coming out to be two.
Ninety one.
Okay, so I hope you know what is typecasting, implicit typecasting.
So let's see some more example.
So implicit typecasting.
Character plus in danger is in in danger.
OK.
Similarly in danger, plus flawed.
Is flawed.
In danger, divided by a flawed.
Is flawed.
And similarly.
Integer divided by integer is an integer, so typecasting means you have flawed.
Then you have integers.
Then you have correctors and then you have bull.
OK?
So cattle can be converted to endanger cattle, can be converted to float.
And similarly, integer can be converted to flawed.
And similarly, Boole can be converted to indicate integer or flawed.
OK, so this is implicit typecasting you you can remember some of the rules.
There is one moral character, plus character is an integer.
Why?
Because this plus operator is defined for integers.
And so it will convert correctly into our Sky-Blue, this character towards Scaevola, and then add
those Wickwire.
And we will get integer as an output.
So let's see some more examples to make things clear.
So first of all, that we will see some more example, character Blaesing Deja.
So how do you find Aaskov a local character?
What we will do?
We will write see out.
For example, I want to find the guy really of character, a capitally.
So what do I do?
Capital.
A place.
Zero.
Okay, so character blessin deja.
My output will be in danger.
So let's bail and then.
So output is sixty five, which is the Aske I value of capitally.
Similarly, you can find Sky-Blue in this faction of any character.
For example, the sea out.
Let's say I want to find does Caverly of Smally.
So please zero.
OK, so 65 and under, because I have not given and line here.
So let's commander doubt and now let's run it again.
Under this deal, I ask I really have character be.
OK, so let's see somewhat example.
For example, if I do get AVC Edge.
It quotes.
Capital A..
And then I am printing C out.
C, H plus one.
So obviously my answer will be.
And line, so hours, I will be 66.
OK, so look.
Ask a value of character is 65 and Pleasant's amount will be 66.
66 is getting printed.
Now, what if I do?
S.H. equals.
S.H. plus one.
And then we are printing CIJ.
So what will be my output?
Let's come into doubt also.
So what will be my output?
OK, so let's run it.
So Capital B is getting rendered midway.
So let's see.
So in this case, my output was 65, sorry, 66.
And in this case.
My out for this.
Capital B..
So in this case, what happened is when you write C out.
S.H. plus one, so the value of S.H. was sixty five and then you are adding one.
So the output was 66.
I already told you.
Character plus integer is an integer.
This is implicit typecasting.
OK, so but Vinnie Relu, S.H. equals S.H. plus one.
So the output of this expression is an integer, no doubt.
OK, so according to this rule.
The value of this expression is an integer, no doubt.
But what you are doing, you are converting this integer into a character, basically integer is a four
bytes.
Okay.
So it is a four bytes.
And what they are doing, you are converting these four bytes.
This integer into this collectivities of one byte.
So the character corresponding to So S.H. plus one is 66.
So the character corresponding to Values 66 is getting matte is getting inserted into this box.
S.H..
Okay, so this is B.
See this part, the output of this is an integer and the character map with integer is getting stored
in two variable S.H. and then you are printing that variable, which is B, let's see one more example
to make things clear.
So what do we do?
S.H., it goes.
C.H., bless them.
OK, so let's build and.
First of all, let's Comando this plane.
And also coming down this line.
So come on.
This line also.
OK.
So the value of variable CS capitally and then you are adding tend to it.
So what will happen.
Billin.
OK, so we are not bringing anything, let's bring something.
She owed.
C.H..
So character is getting printed because that's Kevin of character, avil, character key will be.
Just a second.
This value is.
Capital images 65, you're riding 10 to it.
So S.H. equals C, H, plus 10.
This whole value is 75, OK?
So the character corresponding to 75 is getting stored in variable age, which is key.
And then you are printing this character key here.
OK.
So very easy.
Now, let us see one of the most important thing.
At around.
OK, so what is a wrap around?
Wrap around.
OK.
So I told you character Pless character is an endangered.
Okay, so I told you about this.
So what will happen if you print out?
Character, a plus character.
So where to live my output, my output will be 65 plus 65, which is 130.
No doubt.
But what will happen if you ride?
Cassie H.
Equals capital, a blessed capitally.
I told you that the output of this expression is an integer, which is 130 and the correct, they're
corresponding to 130.
Will be stored in variable CIJ.
But data problem in the last class, I told you that the range of character that the range of character
dirty diapers from minus 128 to 127.
So days and I think all the.
OK.
So what will happen?
So and so what happened is generally this is minus 128, then minus 127, 126 and 127.
So when you are standing here and if you do plus one, 127 plus one, so you will reach here.
Okay, so you are standing at 127, and if you look plus one, you will reach here.
This thing is called wrap around.
Rep.
Around.
OK, so one 27 plus one is minus 128.
Similarly went on to say one plus two is minus 127, went on the seven plus three and it goes to minus
126.
So in this case, this will lose 130.
So the character corresponding to 130 is getting stored in S.H..
And that character is mapped with minus 126.
OK.
So, for example, if you ride can H is it goes to 127.
So the character corresponding to 127 is stored in variable C h.
And then if you do see H equals C, H plus one, that is 127 plus one, which will be close to minus
128 due to wrap around.
So minus went on there, the correct corresponding to minus 128 will be stored in variable C h.
And if you print C, H.
So that correctively blueprinted which is mapped to minus 128.
So this wrap around things happens with another diaper as well.
For example, I told you that the range of integers.
Is from minus two to the power 31 to that about her division minus one.
So this was the range of.
So actually, this thing is called into Max.
And this thing is called Anderman.
So here I am having Anderman.
And you have intermix here.
So if we will add plus one to the endemics, you will reach Intiman.
OK, so this is a wrap around.
And the bank says nothing.
It is just good, it's about doing minus one.
This value has been given some name and that name is in the banks.
Similarly, in is nothing.
It is minus two to the power 31.
It is just Antoin is just the name of this value.
OK, so now let's talk about explicit typecasting.
So implicit typecasting was which was done automatically.
We are not doing anything.
It is done automatically by the compiler.
So I told you, remember this thing flawed.
Then you have integers.
Then you have characters.
And then you have bull.
So from lower to upper.
From lower to upper.
This is called implicit typecasting because these type conclusion are done automatically by the compiler.
But what if I want to do the reverse?
I want to convert integer to character.
So we are doing the reverse.
So this thing will be called explicit typecasting.
OK, so let's see an example.
So for explicit typecasting.
What you will do.
Commander Daoud also.
So for explicit typecasting, what you will do, for example, you are having gay S.H..
It goes like character.
Suppose you want to find you want to convert this character into integer.
You will.
What you will do.
You will just write in.
And then you will write to S.H..
So this thing is called explicit typecasting.
So what is the value of variable?
Well.
It is nothing but 65.
OK, so let's build and lemon.
Sixty 65 is getting printed.
OK.
So this is called explicit typecasting.
We are typecasting ourself.
Let's take let's take one more example, for example, voodoo will be a true.
And X equals.
Typecast.
B.
And then you are printing the value of X.
So what do I my output.
My output will be one.
So when is getting printed?
Why, when?
Because through means one false means zero simple.
Now, let's see one more example.
And way equals 70.
S.H..
It was.
Why and then you are printing C.H..
So where to live my output.
So the value of variable Y is seventy.
And then you'll come out doing that seven days into a character.
So the character mapped with 70 will get printed.
So there is an error in this line.
Oh, so that it is.
We have already declared the variable C.H..
So let's change the name ABC.
A B.S., OK, so you can't have two variables with the same name.
So their character maybe with the 70s Capital F..
OK, so what is the problem?
What is the problem with typecasting?
So the problem is very simple.
Flawed and.
Gad.
And, Wolf, if you're going from lower to upper, if you're converting any lower into upper, in that
case, we don't have any problem.
For example, if you want to convert.
If you want to typecast the character into Integer, what will happen?
This is of one byte and then integer is of four bytes.
So this one bite can easily be copied in this integer.
But as soon as you try and reverse, for example, you want to convert integer in a character in the
last example where there did something like this, also what we did and divide was 70 and.
Can ABC.
Care, right?
So if you want to do this.
So what are you doing?
This is why four bites, and this is my character, just one bite and were destroyed, Windows doing
it will copy only one bite.
Into the character and all this data will be lost.
OK, so in this case, my data is not lost because the variable.
Well, because the variable Y is containing small value and 70 can be written in eight bytes.
So this is Edwards.
And the remaining is gurantee forwards.
So 70 can be written in eight, which that's why there is no details.
But if the number was very large, for example, let's say if the number was this and then if you typecast
this integer into a character, then there will be a detailers.
OK.
So I hope you come to know what is implicit and explicit typecasting.
Typecasting means which is done automatically by the compiler.
For example, character Pless in Bajour is an integer integer divided by a flawed is a flawed and indeed
the less flawed is flawed.
Similarly, integer in character is an integer.
Okay.
And a character.
Pless character is also an integer.
In this case, that Abbadon possibility's there and an explicit typecasting.
What will do?
For example, you will write GABSI h.
As it goes to typecast into character.
And if let's say and Y equals 10, it will write something like this.
Okay, so this is explicit.
We are converging in this case.
This is called implicit.
It is done automatically by the compiler.
And the last thing today that we learned is wrap around.
OK, if you're standing at the maximum value and you will add blessin, you will reach the minimum value.
OK, so this is it for this video.
Thanks for watching.