What is Namespace?

Questions by suji   answers by suji

Showing Answers 1 - 5 of 5 Answers

vivek singh

  • Sep 27th, 2005

Namespace is a collection of Classes and the classes can be predefined or it can be use defined.we can also defined the Namespace.

  Was this answer useful?  Yes


  • Feb 12th, 2014

namespace is a global declarative region which consists of variables,functions,classes etc....

  Was this answer useful?  Yes


  • Oct 3rd, 2016

Suppose we have two libraries lib1 and lib2. let there is a function add() present in both of them, this function can have different meaning or functionality in both libraries but they have same name, so it will be conflicting for compiler which function to call? so namespaces are the ways to remove this conflict. for example

  1. namespace lib1{

  2. add(){....}

  3. }

  4. namespace lib2{

  5. add(){..}

  6. }


  8. int main(){

  9. lib1::add();//it will call add() which belongs to group lib1

  10. lib2::add();//it will call add() which belongs to group lib2

  11. }

  Was this answer useful?  Yes


  • Jul 20th, 2017

We cannot have two variables with the same name in the same scope. To resolve this namespace is introduced.
Namespace is a declarative region that provides a scope to the identifiers inside it. Accessing of these variables can be done using the namespace name::variable name. These namespace declerations appear at global scope.

  1. namespace ns

  2. {

  3.   int val=500;

  4. }

  5. int val=100;

  6. int main()

  7. {

  8.   int val=200;

  9. cout<<ns::val<<endl;

  10. }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions