250+ TOP MCQs on Checked Iterators and Answers

This section on C++ questions and puzzles on “Checked Iterators”. One shall practice these questions and puzzles to improve their C++ programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These programming puzzles 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++ questions come with detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of C++ questions and puzzles on “Checked Iterators” along with answers, explanations and/or solutions:

1. What is the use of checked iterators?
a) Overwrite the bounds of your container
b) Not allow you to overwrite the bounds of your container
c) It will check the list value
d) Overwrite the bounds of your iterators
Answer: b
Clarification: Checked iterators ensure that you do not overwrite the bounds of your container.

2. What will happen if the iterator is unchecked?
a) Arising of compiler warnings
b) Unchecked behavior on program
c) Nothing will execute
d) Arising of compiler warnings & Unchecked behavior on program
Answer: d
Clarification: We will get unchecked behavior on calls to an unchecked function and Calls to the standard function will result in compiler warnings.

3. How many adaptors support the checked iterators?
a) 1
b) 2
c) 3
d) 4
Answer: b
Clarification: There are two adaptors that support checked iterators. They are checked_array_iterator class, Checked_iterator class.

  250+ TOP MCQs on OOPs Concept – 1 and Answers

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

  1.     #include 
  2.     #include 
  3.     #include 
  4.     #include 
  5.     using namespace std;
  6.     int main()
  7.     {
  8.         vector<int> vec;
  9.         vec.push_back(10);
  10.         int i = vec[100];
  11.         try {
  12.             i = vec[0];
  13.             cout << i << endl;
  14.         }
  15.         catch (exception &e)
  16.         {
  17.             cout << "Caught: " << e.what( ) << endl;
  18.             cout << "Type: " << typeid( e ).name( ) << endl;
  19.         }
  20.         catch (...) 
  21.         {
  22.             cout << "Unknown exception: " << endl;
  23.         }
  24.         return 0;
  25.     }

a) 10
b) 100
c) Exception
d) Error
Answer: a
Clarification: In this program, We are pushing the 10th element and printing it.
Output:

$ g++ chei.cpp
$ a.out
10

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

  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         try {
  7.             map<char, int> mymap;
  8.             map<char, int> :: iterator it;
  9.             mymap['a'] = 50;
  10.             mymap['b'] = 100;
  11.             mymap['c'] = 150;
  12.             mymap['d'] = 200;
  13.             it = mymap.find('b');
  14.             mymap.erase (it);
  15.             mymap.erase (mymap.find('d'));
  16.             cout << mymap.find('a') -> second << 'n';
  17.         }
  18.         catch (...) 
  19.         {
  20.             cout << "Unknown exception: " << endl;
  21.         }
  22.         return 0;
  23.     }

a) 50
b) 100
c) 150
d) Exception
Answer: a
Clarification: In this program ,We are finding the element a and printing it.
Output:

$ g++ chei1.cpp
$ a.out
50

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

  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         try {
  7.             double value1, value2;
  8.             istream_iterator<double> eos;       
  9.             istream_iterator<double> iit (cin);   
  10.             if (iit != eos) 
  11.                 value1 = *iit;
  12.             iit++;
  13.             if (iit != eos) 
  14.                 value2 = *iit;
  15.             cout << (value1 * value2) << endl;
  16.         }
  17.         catch (...) {
  18.             cout << "Unknown exception: " << endl;
  19.         }
  20.         return 0;
  21.    }

a) 10
b) 45
c) It will print the multiplied value of the input
d) Exception
Answer: c
Clarification: In this program, We got the input by using istream iterator and we are manipulating in.
Output:

$ g++ chei2.cpp
$ a.out
3
4
12

7. 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.         vector<int> myvector;
  8.         for (int i = 1; i < 4; ++i) 
  9.             myvector.push_back(i*10);
  10.         ostream_iterator<int> out_it (cout,", ");
  11.         copy ( myvector.begin(), myvector.end(), out_it );
  12.         return 0;
  13.     }

a) 10, 20, 30
b) 10, 20
c) 10, 20, 30,
d) 30, 15, 10
Answer: c
Clarification: In this program, We are producing the values by vector and printing it by using ostream iterator.
Output:

$ g++ chei3.cpp
$ a.out
10, 20, 30,

8. 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.         vector<int> myvector;
  8.         for (int i = 0; i < 10; i++) 
  9.             myvector.push_back(i);
  10.         typedef vector<int> :: iterator iter_int;
  11.         reverse_iterator<iter_int> rev_iterator;
  12.         rev_iterator = myvector.rend() - 4;
  13.         cout << *rev_iterator << endl;
  14.         return 0;
  15.     }

a) 2
b) 3
c) 4
d) 5
Answer: b
Clarification: In this program, We are using the referencing operator and it can print the value currently pointing it.
Output:

$ g++ chei4.cpp
$ a.out
3

9. What does the checked iterator allow you to find?
a) Warnings
b) Compile time error
c) Run time error
d) Warnings & Run time error
Answer: c
Clarification: Checked iterator allow you to find Run time error.

10. What kind of errors do checked iterators detect?
a) Uninitialized iterators
b) Initialized iterators
c) Range access
d) Both Uninitialized iterators and range access
Answer: d
Clarification: Checked iterators can easily detect the errors in Uninitialized iterators as well as Range of access.

Leave a Comment

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

Scroll to Top