MCQs
None.
A scope resolution operator without a scope qualifier refers to the global namespace.
We are overriding the value at the main function and so we are getting the output as 55.
Output:
$ g++ name4.cpp
$ a.out
55
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
What is the output of these program?
1.
#include
2.
using namespace std;
3.
namespace first
4.
{
5.
int x = 5;
6.
int y = 10;
7.
}
8.
namespace second
9.
{
10.
double x = 3.1416;
11.
double y = 2.7183;
12.
}
13.
int main ()
14.
{
15.
using first::x;
16.
using second::y;
17.
bool a, b;
18.
a = x > y;
19.
b = first::y < second::x;
20.
cout
We are inter mixing the variable and comparing it which is bigger and smaller and according
to that we are printing the output.
Output:
$ g++ name1.cpp
$ a.out
10
As we are getting two variables from namespace variable and we are adding that.
Output:
$ g++ name.cpp
$ a.out
8
None.
The main aim of the namespace is to understand the logical units of the program and to make
the program so robust.
Namespace allow you to group class, objects and functions. It is used to divide the global
scope into the sub-scopes.
None.