Correct option is A
·
Statement (i): True Namespaces are used to group identifiers such as classes, functions, and variables to avoid
naming conflicts in large programs, especially when combining code from multiple libraries.
·
Statement (ii): True The using directive in C++ (e.g., using namespace std;) allows identifiers within a namespace to be used without explicit qualification, simplifying the code.
·
Statement (iii): False Multiple namespaces can contain the
same identifiers, and they will remain distinct as long as they belong to different namespaces.
For example:
Important Key Points:
1. Namespaces are a feature of
C++ to resolve naming collisions in large programs or projects with multiple libraries.
2. The using directive can lead to potential ambiguity if two namespaces have conflicting identifiers (e.g., value from both A and B).
3. Identifiers in different namespaces are fully qualified by their namespace name (e.g., A::value, B::value).
Knowledge Booster:
·
namespace std: The standard namespace in C++ that contains common features like cout, cin, and string.
·
Nested namespaces: C++ allows namespaces to be nested, e.g., namespace A::B {}.
·
Fully Qualified Names: Accessing identifiers explicitly using the namespace, e.g., std::cout.
