Google News
logo
CPP - Quiz(MCQ)
A)
Minimum float value
B)
Minimum finite value
C)
Maximum finite value
D)
Maximum finite value for a float type

Correct Answer : Option (D) :   Maximum finite value for a float type


Explanation : Max function in the numeric limit will return the maximum finite value for a float type.

2 .
What will be the output of the following C++ code?
    #include <iostream>
    #include <limits>
    using namespace std;
    int main () 
    {
        cout << boolalpha;
        cout << numeric_limits<int> :: has_infinity << '\n';
        return 0;
    }
A)
true
B)
false
C)
32564
D)
53234

Correct Answer : Option (B) :   false


Explaination :

In this program, We are checking whether the integer has limit or not by using has_infinity function.

Output :

false

A)
math
B)
maths
C)
cmath
D)
dmath

Correct Answer : Option (C) :   cmath


Explanation : #include is a header file required for manipulation of math functions.

A)
math
B)
cmath
C)
dmath
D)
vmath

Correct Answer : Option (D) :   vmath


Explanation : vmath is set of C++ classes for Vector and Matrix algebra used in the programs.

A)
Returns the number & result
B)
Returns the result of accumulating all the values in the range
C)
Return the characters
D)
Returns the number

Correct Answer : Option (B) :   Returns the result of accumulating all the values in the range


Explanation : Returns the result of accumulating all the values in the range from first to last.

A)
Difference
B)
Addition
C)
Subtraction
D)
Multiplication

Correct Answer : Option (A) :   Difference


Explanation : The default operation is to calculate the difference, but some other operation can be specified as binary operator instead.

A)
A technique of C++ that allows us to write overloaded functions
B)
A technique of C++ that allows us to write inline functions without a name
C)
A technique of C++ that allows us to write functions without parameters
D)
A technique of C++ that allows us to write functions that are called more than once

Correct Answer : Option (B) :   A technique of C++ that allows us to write inline functions without a name


Explanation : Lambda expression is a technique available in C++ that helps the programmer to write inline functions that will be used once in a program and so there is no need of providing names top them. Hence they are a type of inline functions without names.

A)
[X, Y]
B)
[X, &y]
C)
[&X, Y]
D)
[&x, &Y]

Correct Answer : Option (C) :   [&X, Y]


Explanation : In order to capture a variable by reference we use & operator whereas when we capture a single variable by value then we just write the name of that variable without any operator preceding it, So the correct way of capturing the variables X and Y, in this case, is [&X, Y].

9 .
What will be the output of the following C++ code?
 
#include<iostream>
using namespace std;
int main()
{
	int a = 5;
	auto check = [&]() 
        {
		a = 25;
	};
	check();
	cout<<"Value of a: "<<a<<endl;
	return 0;
}
A)
Value of a: 5
B)
Value of a: 15
C)
Value of a: 20
D)
Value of a: 25

Correct Answer : Option (D) :   Value of a: 25


Explaination : As this lambda expression is capturing the extrenal variable by reference therefore the change in value of a will be reflected back outside the expression therefore the value of a will now be 25 and 25 is printed.

A)
Arguments passed to any function
B)
Arguments passed to class functions
C)
Arguments passed to structure functions
D)
Arguments passed to main() function

Correct Answer : Option (D) :   Arguments passed to main() function


Explanation :

The most important function of C/C++ is main() function. It is mostly defined with a return type of int and without parameters :
 
int main() { /* ... */ } 
 
We can also give command-line arguments in C and C++. Command-line arguments are given after the name of the program in command-line shell of Operating Systems.

To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments.
 
int main(int argc, char *argv[]) { /* ... */ }
or
int main(int argc, char **argv) { /* ... */ }