Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
using namespace std;
3.
namespace Box1
4.
{
5.
int a = 4;
6.
}
7.
namespace Box2
8.
{
9.
int a = 13;
10.
}
11.
int main ()
12.
{
13.
int a = 16;
14.
Box1::a;
15.
Box2::a;
16.
cout
Options:
A .  4
B .  13
C .  16
D .  compile time error
Answer: Option C

In this program, as there is lot of variable a and it is printing the value inside the block 

because it got the highest priority.
Output:
$ g++ name2.cpp
$ a.out
16



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers