Malcolm, in this coding lecture, I'm going to show you an example program that will show you what
shadowing means and how to prevent it.
By the way, shallowing problem is very famous out at least once every gopher has fallen into its wicked
trap.
Let's check it out.
All right, now let's first declare a variable named an.
I'm intentionally selected of its name as an.
It's because this Assif bloke here also uses the name.
Now, let's print variable.
Princess and is integer.
Spookies.
You've been shut out.
OK, if I run this program now, can you guess what will happen next, please post the video and think
about it.
OK, let me show you let's run it with a number like this, 40.
As you can see, it, first prints the correct calculation, then it prints Euronext.
But why?
A beginner golfer usually thinks that the available here is the one that's been declared inside the
main function main functions at.
However, the reality is different in the US branch, this is a new variable in shadows, the main functions
and variable.
This is why it's called the shadow.
It creates another variable.
It's in an inner scope with the same name.
So there are two and variables.
This can be very confusing and it can lead to bugs.
This is happening because of the declaration here, remember, the declaration can declare new variables
and assigned to the existing variables at the same time.
Since this is a new block, it declares variables instead of changing their value.
Can you see this short declaration, operator?
That is the cause of terror.
So how to prevent this problem?
Let me show you.
Let's declare a new era variable like this.
As you can see, variables type is error.
It's a pretty clear type, like int floor 64.
And so let's change this radicalisation into an assignment statement like this.
As you can see, you can also use an assignment statement here, so instead of using Cullen's equal
operator, I've just used the equal operator.
This is the assignment now.
It's voluntary.
Declare new variables here.
Instead, it will just use the variables that belong to the main function, which I just declare the
ball here.
OK, now this is the result, back again to the unwearable.
So that you can see it in the end when I print it.
OK.
All right.
Now, let's run it again, like this 40 is you can see this time it Prince 80 correctly.
So now there isn't any Qadam issue now.
There is only one viable, not so you can use the embeddable even after the if statement, as you've
seen here and now, since the army belongs to the main function, and if statement is inside of the
main function, both the main function and the if statement can see and changed the same and variable.
That's why it brings 80 instead of zero.
By the way, go and let you know about the Shadmi problem automatically if you configure your escort.
Let me show you how it works.
Go to the View menu here and select this comment, Pelletiere.
Then type settings, then select this one, open settings, Jason.
And here, go to the bottom of this configuration file.
And type this very same configuration options.
If they exist already, just change them with this, then just save the file.
For example, here, it tells me that there is a shadowing problem and it shows me the exact location
of the problem.
So here it tells me that these light shuttles available declared at these light.
So Galvan's me, that's the honorable of the if statement châteaux the main funks and rebel this way
you can catch most of the shallowing errors when they happen.
All right.
I hope now you understand the upshot of.
Congrats.
Now, you know what's a simple statement?
How Scottsburg made it and the famous shot, I mean, gotcha, OK, see in the next picture by.