C++ Programming Multiple Choice Question - Namespaces

This section focuses on the "Namespace" in C++ programming langauge. These Multiple Choice Questions (MCQ) should be practiced to improve the C++ programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. Which operator is used to signify the namespace in c++?

A. conditional operator
B. ternary operator
C. scope operator
D. None of the mentioned

View Answer


2. Identify the incorrect statement?

A. Namespace is used to mark the beginning of the program
B. Namespace is used to mark the beginning & end of the program
C. A namespace is used to separate the class, objects
D. All of the above

View Answer


3. What is the use of Namespace?

A. To encapsulate the data
B. Encapsulate the data & structure a program into logical units
C. It is used to mark the beginning of the program
D. None of the above

View Answer


4. What is the general syntax for accessing the namespace variable?

A. namespace::operator
B. namespace,operator
C. namespace#operator
D. namespace$operator

View Answer


5. The use of Namespace is to structure a program into logical units?

A. TRUE
B. FALSE
C. May Be
D. Can't Say

View Answer


6. Which of the following is correct option?

#include<iostream>
using namespace std;
namespace lfc1
{
    int var = 30;
}
namespace lfc2
{
    double var = 13.5478;
}
int main ()
{
    int a;
    a = lfc1::var + lfc2::var;
    cout << a;
        return 0;
 }

A. 43.5478
B. 43
C. 44
D. 30

View Answer


7. Which of the following is correct option?

    #include<iostream>
    using namespace std;
    namespace lfc1
    {
        double var =30.1234;
    }
    namespace lfc2
    {
        double var = 13.5478;
    }
    int main ()
    {
        double a;
        a = lfc1::var - lfc2::var;
        cout << a;
        return 0;
   }

A. 16.5756
B. 17
C. 15
D. 16.57

View Answer


8. Which of the following is correct option?

    #include<iostream>
    using namespace std;
    namespace lfc1
    {
        int x = 10;
    }
    namespace lfc2
    {
        int x = 20;
    }
    int main ()
    {
        int x = 30;
        lfc1::x;
        lfc2::x;
        cout << x;
        return 0;
    }

A. 30
B. 20
C. 10
D. Compile Error

View Answer


9. Which of the following is correct option?

    #include<iostream>
    using namespace std;
    namespace lfc
    {
        int x = 10;
    }
    namespace lfc
    {
        int x = 20;
    }
    int main ()
    {
        int x = 30;
        lfc::x;
        lfc::x;
        cout << x;
        return 0;
    }

A. 30
B. 20
C. 10
D. Compile Error

View Answer


10. Which keyword is used to access the variable in the namespace?

A. using
B. dynamic
C. const
D. static

View Answer





Also check :


Discussion


* You must be logged in to add comment.