My Report

C++ Iterators Test – 3


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Which of the following is an advantage of Forward iterator over input and output iterator?

2. Which of the following is correct?

3. What are Bi-directional iterators?

4. Which of the following is correct about Input Iterators?

5. Which function is used increment the iterator by a particular value?

6. What type of Iterator i1 is in the following C++ code snipet?

================ code ================
vector<int>::iterator i1; 
for (i1=v1.begin();i1!=v1.end();++i1) 
	*i1 = 1;
======================================

7. What are Random-access Iterators?

8. Pick the correct statement.

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

#include<iostream> 
#include<iterator> 
#include<vector> 
using namespace std; 
int main() 
{ 
    vector<int> ar = { 1, 2, 3, 4, 5 }; 
    vector<int>::iterator ptr = ar.begin(); 
    ptr = advance(ptr, 2);
    cout << *ptr << endl; 
    return 0; 
} 

10. How many types of Iterators are there?

11. Which of the following is correct about Input Iterators?

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

#include<iostream> 
#include<iterator> 
#include<vector> 
using namespace std; 
int main() 
{ 
    vector<int> ar = { 1, 2, 3, 4, 5 }; 
    vector<int>::iterator ptr = ar.begin(); 
    ptr = next(ptr, 3);
    cout << *ptr << endl; 
    return 0; 
} 

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

#include<iostream> 
#include<iterator> 
#include<vector> 
using namespace std; 
int main() 
{ 
    vector<int> ar = { 1, 2, 3, 4, 5 }; 
    vector<int>::iterator ptr = ar.begin(); 
    advance(ptr, 2);
    cout << *ptr << endl; 
    return 0; 
}

14. What are Iterators?

15. If i1 is Input Iterator and i2 is Output Iterator, then which of the following things are correct?

i) cout<<*i1;
ii) i2 can be used with == operator
iii) *i1 = 1
iv) i2--

 

Start practicing “1000 MCQs on C++”, and once you are ready, you can take tests on all topics by attempting our “C++ Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.