Question: What will the following program display? #include using namespace std; void other(); namespace n1 { int x = 1; } namespace n2 { int x
What will the following program display?
#include
using namespace std;
void other();
namespace n1
{
int x = 1;
}
namespace n2
{
int x = 2;
}
int main()
{
using namespace n1;
cout << x << endl;
{
int x = 4;
cout << x << ", " << n1::x << ", " << n2::x << endl;
}
using n2::x;
cout << x << endl;
other();
return 0;
}
void other()
{
using namespace n2;
cout << x << endl;
{
int x = 4;
cout << x << ", " << n1::x << ", " << n2::x << endl;
}
using n2::x;
cout << x << endl;
}
Step by Step Solution
3.56 Rating (167 Votes )
There are 3 Steps involved in it
The program will display 2 2 4 2 2 4 The other function is written in the namespace n2 and hence has ... View full answer
Get step-by-step solutions from verified subject matter experts
