C++ Namespace

Write output with explanation.

namespace xyz
{
     int x = 10 ;
}
void main ( )
{
     int y = 200 ;
     int x = 100;
     cout<<endl <<"x="<< x;
     usingnamespace xyz;
     cout<< endl<<"x="<< x;
     cout<<endl<<"y="<< y;
}

Output:

x = 100
x = 100
y = 200

Description:

In the above program, same name variable x is defined in namespace xyz and in main function. Here namespace xyz is used in main function but local variable x has higher priority. So compiler will use int x = 100 while displaying, not x = 10. If you remove the local variable int x = 100 from main function, then it will take int x = 10 from namespace xyz.