250+ TOP MCQs on Min and Max and Answers

This section on tough C++ programming questions on “Min and Max”. One shall practice these questions to improve their C++ programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ programming questions come with detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of tough C++ programming questions on “Min and Max” along with answers, explanations and/or solutions:

1. Which keyword is used to declare the min and max functions?
a) iostream
b) string
c) algorithm
d) iterator
Answer: c
Clarification: Algorithm header file contains the supporting files needed for the execution of these functions.

2. What kind of functions are min and max in c++?
a) Type specific
b) Variable specific
c) Type & Variable specific
d) Iterator
Answer: a
Clarification: The min/max functions are type specific but they will not force everything to be converted to/from floating point. The functions that will force everything to be converted to/from floating point are fmin/fmax.

3. How many parameters are needed for minmax function?
a) 1
b) 2
c) 3
d) All of the mentioned
Answer: d
Clarification: The “minmax” function can take the following:
1 parameter: An initializer_list object.
2 parameters: Values to compare.
2 parameters: An initializer_list object. and comparison function
3 parameters: Values to compare. and comparison function

  250+ TOP MCQs on Constructors and Destructors – 2 and Answers

4. What will be the output of the following C++ code?

  1.     #include    
  2.     #include   
  3.     using namespace std;
  4.     int main () 
  5.     {
  6.         cout << "max(1, 2) == " << max(1, 2) << 'n';
  7.         cout << "max('a', 'z') == " << max('a', 'z') << 'n';
  8.         return 0;
  9.     }

a) 2z
b) 2a
c) Error
d) 2y
Answer: a
Clarification: In this program, We found the max value in the given value by using max function.
Output:

$ g++ max.cpp
$ a.out
max(1, 2) == 2
max('a', 'z') == z

5. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     bool myfn(int i, int j) 
  5.     {
  6.         return i < j;
  7.     }
  8.     int main () 
  9.     {
  10.         int myints[ ] = {3, 7, 2, 5, 6, 4, 9};
  11.         cout <<  *min_element(myints, myints + 7, myfn) << 'n';
  12.         cout << *max_element(myints, myints + 7, myfn) << 'n';
  13.         return 0;
  14.     }

a) 2 9
b) 2 7
c) 3 9
d) 3 5
Answer: a
Clarification: In this program, We found out the minimum value and maximum value
of a range.
Output:

$ g++ max1.cpp
$ a.out
2 
9

6. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     #include 
  4.     using namespace std;
  5.     int main () 
  6.     {
  7.         int myints[] = {10, 20, 30, 30, 20, 10, 10, 20};
  8.         vector<int> v(myints, myints + 8);
  9.         sort (v.begin(), v.end());
  10.         vector<int> :: iterator low, up;
  11.         low = lower_bound (v.begin(), v.end(), 20);
  12.         up = upper_bound (v.begin(), v.end(), 20);
  13.         cout << (low - v.begin()) << ' ';
  14.         cout << (up - v.begin()) << 'n';
  15.         return 0;
  16.     }

a) 3 6
b) 2 5
c) 2 6
d) 2 4
Answer: a
Clarification: In this program, We are finding the upper bound and lower bound values by using lower_bound and upper_bound methods.
Output:

$ g++ max2.cpp
$ a.out
3 6

7. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         cout << min(2, 1) << ' ';
  7.         cout << min('m','m') << 'n';
  8.         return 0;
  9.     }

a) Error
b) Runtime error
c) 1 m
d) 5 m
Answer: c
Clarification: In this program, We are finding the minimum value by using min method.
Output:

$ g++ max3.cpp
$ a.out
1 m

8. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     #include 
  4.     using namespace std;
  5.     bool mygreater (int i,int j) 
  6.     {
  7.         return (i > j);
  8.     }
  9.     int main () 
  10.     {
  11.         int myints[] = {10, 20, 30, 30, 20, 10, 10, 20};
  12.         vector<int> v(myints, myints + 8);
  13.         pair<vector<int> :: iterator, vector<int> :: iterator> bounds;
  14.         sort (v.begin(), v.end());
  15.         bounds = equal_range (v.begin(), v.end(), 20);
  16.         cout  << (bounds.first - v.begin());
  17.         cout << " and " << (bounds.second - v.begin()) << 'n';
  18.         return 0;
  19.     }

a) 3 and 6
b) 2 and 5
c) 3 and 5
d) 2 and 4
Answer: a
Clarification: In this program, We are finding out the equal range in the vector.
Output:

$ g++ max4.cpp
$ a.out
3 and 6

9. Which function is used to return the minimum element in the range?
a) min
b) minimum
c) min_element
d) max_element
Answer: c
Clarification: The min_element is used to compare the range of elements and it can find out the minimum element.

10. Which operator is used to compare the values to find min and max?
a) <
b) >
c) <<
d) >>
Answer: a
Clarification: Less than(<) operator is sufficient to compare any two elements in heap and construct respective min or max heap accordingly.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top