Namespace In C++

Definition of Namespace

A namespace (sometimes also called a name scope) is an abstract container or environment created to hold a logical grouping of unique identifiers or symbols (i.e., names).


➦Namespaces allow us to group named entities that otherwise would have global scope into narrower scopes, giving them namespace scope.

➦A namespace is designed to overcom this difficulty and is used as additional information to differentiate similar functions, classes, variables etc. with the same name available in different libraries.

➦Namespaces allow to group entities like classes, objects and functions under a name. This way the global scope can be divided in "sub-scopes", each one with its own name.

➦Namespace is a container for identifiers. It puts the names of its members in a distinct space so that they don't conflict with the names in other namespaces or global namespace.

Example 1:



Output:

	
 f of Y namespace
 f of X namespace
 

Example 2:



Output:

 5
 2.7183
 10
 3.1416