Hey, guys, what's up?
So in this video, we will learn a new concept called By Value.
So it is very important, so pay attention.
So we'll try to understand this concept with the help of an example.
So suppose my question is right to function.
We have to write a function.
To slap two numbers.
OK, so our aim is to write a function to slap two numbers.
So let us write the code.
So.
Void that isn't able to function will be void because it is not going to return anything.
Let's say the name of the function is my SEP.
And I am digging to numbers as input.
And how does that two numbers, so them, because A equals B and B equals temp.
OK.
So they we lose the slabbed and let's say I'm calling this function from mean, so Intiman led to the
value of is five and the value of B is seven.
And I'm calling function my step.
So my SPREP.
A and B is input.
Now let us burn the valley off A and B.
So what do you think?
Where do live my output?
So I believe it should happen.
The value of NDB should be swept.
So if the value of is five, the new video feature becomes seven.
If the value of BES seven, the new value of B should become five so badly, they should be more output.
Now, let's see what will be my output.
So I am naming this file as called by value.
Now, let's say that doing a Mozart and a quiz.
So An and and B equals five.
So these are the two numbers.
And let's to the name of the function is my step.
And I will give A and B as input.
OK.
Now let us write code for swapping.
So avoid my ASVAB.
It will take two numbers as input and then we will write those three magical lines.
So and --, because A A equals B.
And B equals temp.
So with the help of these three magical lines, the village of NDB will be swept.
OK.
So let us try to bend the values of NDB.
So before swapping C out.
Before stepping.
So before slapping the value of let's spend the value of NDB.
And also, let us rent the video, Flanby after sipping.
So after sipping.
So this is my entire record.
Let's see where the live output.
Before Sepi.
OK.
So before supping, we lose our seven and five.
And after sipping again, the values are seven and five.
So the values are not getting swept.
Now, let us spend here the values of sources out in function.
Now in a desert in the valley of a be here.
And let's see where the values are getting Sabga.
Not so easy out.
And similarly, let us also, Brent, before stepping so.
So in function, let's call it before before stepping.
OK?
And let's call it after stepping.
So let's see whether my whether there is an issue with Mizer function or not.
So before stepping so in faith, these were the initial values here.
Now I'm in function.
So before stepping the religion, so in fact, the seven and five correct after seven, that we lose
our faith in seven.
Then how these values become seven and five.
As soon as I add each mean function.
So justice again.
Let's sprint real loose correctly.
So before stepping in men in main function and after stepping in main function.
Now let's see again.
So before stepping in main function, the values are seven and five in function before slipping the
values.
So in five, correct.
After stepping, will this become five and seven?
But as soon as I reach function, mean the values become seven and five again.
So basically there is no effect of stepping back by.
So let me show you how it is happening.
So.
I am calling this function myself.
So in main function.
This is A this is B, where does the real of A seven?
What is the value of B five?
Then I told you that this A and this A, they both are different.
So since they are different, they will be allocated different memory and the values are getting copied
the way Leo Fey is getting copied.
So a seven a.
Similarly, this bee and this bee, they are different, only their values are getting copied.
So five, now I am doing these kinds of stuff.
Now this is the main part swapping.
So what will happen?
I will take a variable temp.
And sipping, will they please?
OK, so slapping will take place.
The new belly of the new well, your fee will become five.
And the value of.
So this is Gosbee.
So the value of B will become seven.
So the values are getting swept and now I am printing the new values.
So five and seven will get printed.
Initial the value was seven and five.
So this is correct.
Now, at this point of time, this function and.
Since this function and this whole thing goes, this whole thing is popped out of the stack.
If you remember.
So this whole thing is popped out of the stack.
I will reach at this line after swiping the values of A and B are again, seven and five.
So there is no effect of all this on the values of A and B..
So my step function is wrong.
OK, so this thing is called gold by value, you call by value.
And the name is justified because we are just giving the values.
We are just passing on the values.
Seven.
And similarly, we are just calling the function by values.
We are giving values.
OK.
So here I was giving seven value and I was giving five value.
So we are calling the function by value.
Now, how we can correct our approach.
So how to solve this problem?
I want to do swapping.
So how against all this problem, this we will see in the next video.
OK.
Thank you.