A namespace is a scope region which contains names. A namespace identifies where the particular name (a function, types etc).

A namespace can only have declarations and definitions. It does not allow executable statements such as assignments, as shown below.

int b;
b = 1;
 
int main()
{
  return 0;
}

b = 1 gives compilation error as it is an executable statements being used in global namespace.

std namespace

This is standard library namespace where we use std::cin and std::cout. :: is called scope resolution operator. Left operand tells the namespace and right tells the name in the namespace.

If used without left operand, it takes global namespace by default. For example,

#include <iostream>
 
int b{1};
 
int main()
{
  std::cout << ::b; // uses b from global namespace.
  return 0;
}

using-directive (avoid it)

We can use using namespace std; statement to not mention namespace. With this we can directly refer the names defined in the namespace.

#include <iostream>
 
using namespace std;
 
int b{1};
 
int main()
{
  cout << ::b;
  return 0;
}

However, we should avoid using it, as it defeats the purpose of having namespace in c++.

References

  1. https://www.learncpp.com/cpp-tutorial/naming-collisions-and-an-introduction-to-namespaces/