Namespaces(C++ Programming ) Questions and Answers
Explanation:-
Answer: Option C. -> 55We are overriding the value at the main function and so we are getting the output as 55.
Output:
$ g++ name4.cpp
$ a.out
55
Explanation:-
Answer: Option C. -> 16In 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
Question 5.
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
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
Explanation:-
Answer: Option D. -> 10We 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
Explanation:-
Answer: Option B. -> 8As we are getting two variables from namespace variable and we are adding that.
Output:
$ g++ name.cpp
$ a.out
8