Google News
logo
CPP - Quiz(MCQ)
A)
scope operator
B)
bitwise operator
C)
conditional operator
D)
ternary operator

Correct Answer : Option (A) :   scope operator


Explanation :

Scope operator(::) is used in namespace syntax.
General syntax :
namespace X{ int a;}
cout<<X::a;

A)
try
B)
catch
C)
throw
D)
handlers

Correct Answer : Option (D) :   handlers


Explanation : When an exception is arisen mean, the exception is caught by handlers and then it decides the type of exception.

3 .
What is the return value of f(p, p) if the value of p is initialized to 5 before the call?
int f(int&x, int c) {  
c  = c - 1;  
if (c == 0) return 1;  
   x = x + 1;  
return f(x, c) * x;  
}  
Note that the first parameter is passed by reference, whereas the second parameter is passed by value.
A)
3024
B)
6561
C)
55440
D)
161051

Correct Answer : Option (B) :   6561


Explaination : In the given C++ program, we can clearly see that the c is passed by the value, but the x is passed by the reference. Therefore all functions in the given program will have the same copies of the x but different copies of the c.

A)
The function has several static variables
B)
Functions are large and contain several nested loops
C)
Usually, it is small, and we want to avoid the function calls
D)
All of the above

Correct Answer : Option (C) :   Usually, it is small, and we want to avoid the function calls


Explanation : In general, the inline functions are very small in size and more often used in the place of the macros as they are the substitute of the macros and many times better than the macros.

A)
Not possible
B)
By making the destructor private.
C)
By making the constructor private.
D)
By making both constructor and destructor private.

Correct Answer : Option (B) :   By making the destructor private.


Explanation :

One can make a c++ program in which a class's object can be created using only the " new "operator, and still, if the user wants and tries to create its object directly, the program will produce a compiler error. To can understand it more clearly, you can consider the following given example.
 
Example
 
// in this program, Objects of test can only be created using new
class Test1
{
private:
    ~Test1() {}
friend void destructTest1(Test1* );
};

// Only this function can destruct objects of Test1
voiddestructTest(Test1* ptr)
{
deleteptr;
}

int main()
{
    // create an object
    Test1 *ptr = new Test1;

    // destruct the object
    destructTest1 (ptr);

return 0;
}​

A)
Members
B)
Data
C)
Object & data
D)
None of the above

Correct Answer : Option (A) :   Members


Explanation : The data members declared within the structure are known as the members. 

A)
1
B)
2
C)
3
D)
4

Correct Answer : Option (C) :   3


Explanation : There are three types of linkage in c++. They are an internal linkage, external linkage, and no linkage.

A)
internal linkage
B)
external linkage
C)
no linkage
D)
internal & external linkage

Correct Answer : Option (D) :   external linkage


Explanation : In the external linkage, it is used to refer to identifiers in various programs.

A)
variable
B)
code
C)
declaration
D)
prototype

Correct Answer : Option (D) :   prototype


Explanation : By defining a function’s prototype in another file means, we can inherit all the features from the source function.

A)
cpp
B)
h
C)
hf
D)
hg

Correct Answer : Option (B) :   h


Explanation : .h extensions are used for user defined header files. To include a user defined header file one should use #include"name.h" i.e. enclosed within double quotes.