1#include <iostream>
2
3using namespace std;
4
5int main()
6{
7 cout << "Hello World";
8 system("pause");
9 return 0;
10
11}
1Namespaces avoids name collisions bacause of large libraray in c++.
2This feature was not supported in C
1A namespace is a declarative region that provides a scope to the
2 identifiers (the names of types, functions, variables, etc) inside
3 it. Namespaces are used to organize code into logical groups and to
4 prevent name collisions that can occur especially when your code base
5 includes multiple libraries
1//namespace is a declarative region to provide scope for identifiers
2#include <bits/stdc++.h>
3
4using namespace std; //including namespace std for cin and cout
5//my custom namespace for variables and functions
6namespace abc
7{
8 void fun()
9 {
10 cout<<"Hello world"<<endl;
11 }
12 int x=10;
13}
14using namespace abc;
15int main()
16{
17 cout<<10;
18 fun();
19 return 0;
20}
1#include <iostream>
2using namespace std;
3namespace square{
4 int x;
5 int y;
6}
7int main(){
8 using namespace square;
9 x = 10;
10 y = 0;
11 cout << x << y << endl;
12}