Easy learning with example program codes

CPP Namespaces

A namespace in CPP is used to define a scope in order to differentiate similar functions, classes, variables etc. to define the context in which names are defined for the same name available in different libraries.

Syntax: Defining Namespace

namespace namespace_name

// code declarations


Syntax: Calling the defined name

namespace_name  :: code;  // code could be variable or function.



#include <iostream>  
using namespace std;  
namespace str1 {    
void display() {   
cout<<"I am the First String!"<<endl;     	 
namespace str2  {    
void display() {   
cout<<"I am the Second String!"<<endl;   
int main()  
return 0;  


I am the First String!                                                                    
I am the Second String!
Posted in CPP   

Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at


We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki