What is the main purpose of a namespace in C++?
Show answer
Correct answer B
A namespace in C++ is used to organize code into logical groups. It helps avoid name conflicts when different parts of code use the same names. For example, two libraries can have functions with the same name but in different namespaces. The std namespace (e.g., std::cout) is a common example. Namespaces improv e code clarity and maintainability.