Because it prevent name collisions that can occur especially when our code base includes multiple libraries. Using namespaces, All identifiers at namespace scope are visible to one another without qualification.
Formally:A namespace is designed to overcome this difficulty and is used as additional information to differentiate similar functions, classes, variables etc. with the same name available in different libraries. Using namespace, you can define the context in which names are defined. In essence, a namespace defines a scope.