Namespace
What is Namespace in C++?
Explanation
Namespace is a new concept introduced by the ANSI C++ standards committee. For using identifiers it can be defined in the namespace scope as below.
Syntax:
using namespace std;
In the above syntax "std" is the namespace where ANSI C++ standard class libraries are defined. Even own namespaces can be defined.
Syntax:
namespace namespace_name
{
//Declaration of
// variables, functions, classes, etc.
}
Example :
#include <iostream.h> using namespace std; namespace Own { int a=100; } int main() { cout << "Value of a is:: " << Own::a; return 0; } |
Result :
Value of a is:: 100
In the above example, a name space "Own" is used to assign a value to a variable. To get the value in the "main()" function the "::" operator is used.