0

What is the purpose of namespace before main function???

purpose of namespace

2nd Nov 2016, 3:10 AM
Nav Eed
Nav Eed - avatar
7 Answers
+ 5
Ok.. suppose there are two persons with the same name in a classroom. Now if the teacher calls the name it will create confusion as who among the two needs to respond. The solution would be to call the name by mentioning the location where the student is... say 1st bench etc... Similarly in C++, namespace is used to deal with such confusions as there may be variables with the same name.
2nd Nov 2016, 5:51 AM
Partha Bhatta
Partha Bhatta - avatar
+ 4
Also defining a namespace shortens your code. Instead of using "std::cout" you can just use "cout".
2nd Nov 2016, 5:58 AM
nedas
nedas - avatar
+ 3
To avoid confusion ,instead of using std::cout we use cout its easy compare to writing std::cout
2nd Nov 2016, 10:40 AM
sadiya zainab
sadiya zainab - avatar
+ 2
namespace is used to define the boundary within which the variables and functions used inside the program exists...
2nd Nov 2016, 5:30 AM
Partha Bhatta
Partha Bhatta - avatar
+ 1
U r welcome 😊
2nd Nov 2016, 5:58 AM
Partha Bhatta
Partha Bhatta - avatar
0
can you please teach me in easy way??
2nd Nov 2016, 5:46 AM
Nav Eed
Nav Eed - avatar
0
Thank you so much .. you solved my problem! :)
2nd Nov 2016, 5:55 AM
Nav Eed
Nav Eed - avatar