When I run this below code snippet, the output is a is 6. But since I have used namespace n1, which also has variable by name "a", shouldn't the output be a is 5. Am I missing something ?
#include <iostream>
using namespace std;
namespace n1{
int a = 5;
}
int main(void){
int a = 6;
using namespace n1;
cout<<"a is "<<a<<endl;
return 0;
}
But if I use fully qualified name in cout i.e cout<<"a is "<<n1::a; the output is as expected i.e. 5. What is the purpose of using namespace ?