I'm no offense to my general myself, but when we write big program, so in that program we write,
we use multiple variables, we use many functions and also we define many classes.
If we are defining when we are using multiple classes, functions are variables.
So there are chances that they will be complex in between the names of variables, and because of that
we may get errors.
So how to avoid such kind of naming complex.
So for that in various programming languages, various techniques are provided, for example, in C++
language.
But we will see some examples.
So see, here in this code we have defined this value variable.
So here also we are defined here.
Also we are defined here also defined.
So whenever there is a global variable and local variable, so preference is always one to local variable.
Now this is a valid variable and we all look at it 200.
And this value variable, we are allocated 300, but at the same name is used there.
So definitely when we run that it will take value for this well.
But I want to differentiate this well and this will go to differentiate it.
I have mentioned I have defined this value variable in this namespace.
So whenever so see here we'll run this program so normally when we write this and when we compile this
program.
So here you can see here we got output 200.
Now see, but I don't want this variable.
I want to access this very variable so I can take help of this namespace, as I mentioned here.
So I can write here and I can use this resolution operator.
So I will compile this.
And so this time I got 300.
So here we have use namespace for the variable.
In the same way we can use namespace for the function.
So here you can see here we have defined function value.
And again, we are defining the function.
But working of this two value function are different, but names are same so I can differentiate them
by using namespace.
So I have defined this value function in one namespace and this value function in another namespace
and how it is accessed by the name of the namespace.
So see, this is in this one and this value function.
This is true and this value function.
And also here we are using this variable X by using this namespace name in.
So we'll see output of this program.
So here you can see this.
So here we are getting a five year, 200 and extended 100.
We can also use namespace for the cloud.
So here you can see in this program two classes are defined.
This is one sample class and this is another sample class.
Both are the same name.
So to differentiate it, we have this different namespace.
So we mentioned this sample class in this namespace and this in this namespace.
In this one we mentioned we are defined another class sample while using while creating variable our
object of these classes we have to use name of the namespace.
So see, here, we run this program.
We have compiled this and now we will.
So this is for a sample class of this first sample class.
Here you can see this method of first sample class.
And this is from the sample class of another sample that we are defined in namespace instance.
So in namespace we can have variables, we can have functions and we can help classes also.
So to differentiate among different classes, variables and functions, we can use this namespace.
So that is how namespace is used in C++ language.