CPP

CPP

Namespaces has 10 Questions
Which operator is used to signify the namespace?

conditional operator
ternary operator
scope operator
none of the mentioned
Identify the correct statement.

Namespace is used to group class, objects and functions.
Namespace is used to mark the beginning of the program.
Namespace is used to seperate the class, objects.
None of the above
What is the use of Namespace?

To encapsulate the data
To structure a program into logical units.
Both a and b
none of the mentioned
What is the general syntax for accessing the namespace variable?

namespaceid::operator
namespace,operator
namespace#operator
none of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     namespace first
  4.     {
  5.         int var = 5;
  6.     }
  7.     namespace second
  8.     {
  9.         double var = 3.1416;
  10.     }
  11.     int main ()
  12.     {
  13.         int a;
  14.         a = first::var + second::var;
  15.         cout << a;
  16.         return 0;
  17.    }

8.31416
8
9
compile time error
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 << a << b;
  21.         return 0;
  22.     }

11
01
00
10
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 << a;
  17.         return 0;
  18.     }

4
13
16
compile time error
What is the output of this program?
  1.     #include 
  2.     using namespace std
  3.     namespace space
  4.     {
  5.         int x = 10;
  6.     }
  7.     namespace space
  8.     {
  9.         int y = 15;
  10.     }
  11.     int main(int argc, char * argv[])
  12.     {
  13.         space::x = space::y =5;
  14.         cout << space::x << space::y;
  15.     }

1015
1510
55
compile time error
Which keyword is used to access the variable in namespace?

using
dynamic
const
static
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     namespace extra
  4.     {
  5.         int i;
  6.     }
  7.     void i()
  8.     {
  9.         using namespace extra;
  10.         int i;
  11.         i = 9;
  12.         cout << i;
  13.     }
  14.     int main()
  15.     {
  16.         enum  letter { i, j};
  17.         class i { letter j; };
  18.         ::i();
  19.         return 0;
  20.     }

9
10
compile time error
none of the mentioned