Interview Question

What is a namespace used for?

Namespaces organize names and prevent unwanted collisions.

💡 Concept ✅ Quick Revision 🧠 C++

Answer

A namespace provides a declarative region for grouping names. • It helps prevent collisions between libraries and application code. • A qualified name such as graphics::Point selects a namespace member. • Unnamed namespaces give names internal linkage within a translation unit.

💡 C++ Example

namespace geometry { struct Point { int x; int y; }; } geometry::Point origin{0, 0};

⚡ Quick Revision

Namespaces organize names and prevent unwanted collisions.