C++ Programming :: Namespaces

Home > C++ Programming > Namespaces > General Questions

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

1 / 12

 Which operator is used to signify the namespace?

Aconditional operator

Bternary operator

Cscope operator

Dnone of the mentioned

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

2 / 12

 Identify the correct statement

ANamespace is used to group class, objects and functions.

BNamespace is used to mark the beginning of the program.

CNamespace is used to seperate the class, objects.

DNone of the above

Answer: Option A

Explanation:

Namespace allow you to group class, objects and functions. It is used to divide the global scope into the sub-scopes.

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

3 / 12

 What is the use of Namespace?

ATo encapsulate the data

BTo structure a program into logical units.

CBoth a and b

Dnone of the mentioned

Answer: Option B

Explanation:

The main aim of the namespace is to understand the logical units of the program and to make the program so robust.

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

4 / 12

 What is the general syntax for accessing the namespace variable?

Anamespaceid::operator

Bnamespace,operator

Cnamespace#operator

Dnone of the mentioned

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

5 / 12

 Which keyword is used to access the variable in namespace?

Ausing

Bdynamic

Cconst

Dstatic

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

6 / 12

 What is the output of the below C++ program?

#include
using namespace std;
namespace Box1
{
int a = 4;
}
namespace Box2
{
int a = 13;
}

int main ()
{
int a = 16;
Box1::a;
Box2::a;
cout << a;
return 0;
}

A4

B13

C16

DCompilation Error

Answer: Option C

Explanation:

There is lot of variable a and it is printing the value inside the block because it got the highest priority.

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

7 / 12

 What is the output of the below C++ program?

#include
using namespace std;
namespace first
{
int var = 5;
}
namespace second
{
double var = 3.1416;
}
int main ()
{
int a;
a = first::var + second::var;
cout << a;
return 0;
}

A8.31416

B8

C9

DCompilation Error

Answer: Option B

Explanation:

Two variables from namespace variable and we are adding that.

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

8 / 12

 What is the output of the below C++ Program?

#include
using namespace std;
namespace first
{
int x = 5;
int y = 10;
}
namespace second
{
double x = 3.1416;
double y = 2.7183;
}
int main ()
{
using first::x;
using second::y;
bool a, b;
a = x > y;
b = first::y < second::x;
cout << a << b;
return 0;
}

A11

B1

C0

D10

Answer: Option D

Explanation:

We are inter mixing the variable and comparing it which is bigger and smaller and according to that we are printing the output.

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

9 / 12

 What is the output of the below C++ program?

#include
using namespace std
namespace space
{
int x = 10;
}
namespace space
{
int y = 15;
}
int main(int argc, char * argv[])
{
space::x = space::y =5;
cout << space::x << space::y;
}

A1015

B1510

C55

DCompilation Error

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

10 / 12

 What is the output of the below C++ program?

#include
using namespace std;
namespace extra
{
int i;
}
void i()
{
using namespace extra;
int i;
i = 9;
cout << i;
}
int main()
{
enum letter { i, j};
class i { letter j; };
::i();
return 0;
}

A9

B10

C11

DCompilation Error

Answer: Option A

Explanation:

cope resolution operator without a scope qualifier refers to the global namespace.

Workspace