My Report

C++ STL Test – 1


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 type of list a Forward_list sequence container implements?

2. What is the syntax of declaraing a forward_list?

3. How many list sequence containers are provided by STL?

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

#include <iostream> 
#include <vector> 
#include <forward_list>  

using namespace std; 
  
int main() 
{ 
    forward_list<int> fl1;
    fl1.assign(5,10);
    for (int&c : fl1)  
        cout << c << " ";
    cout<<endl;
    fl1.insert_after(fl1.begin(), {1,2,3});
    for (int&c : fl1)  
        cout << c << " ";
    cout<<endl; 
    return 0; 
} 

5. How the list differs from vectors?

6. Which of the following header file is required for forwawrd_list?

7. Which type of list a List sequence container implements?

8. Which of the following(s) is/are the correct way of assigning values to a forward_list f?

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

#include <iostream> 
#include <vector> 
#include <forward_list>  

using namespace std; 
  
int main() 
{ 
    forward_list<int> fl1 = {1,2,3,4,5};
    for (int&c : fl1)  
        cout << c << " ";
    cout<<endl;
    forward_list<int>::iterator ptr = fl1.begin(); 
    fl1.erase_after(ptr);
    for (int&c : fl1)  
        cout << c << " ";
    cout<<endl;
    return 0; 
} 

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

#include <iostream> 
#include <vector> 
#include <forward_list>  

using namespace std; 
  
int main() 
{ 
    forward_list<int> fl1 = {1,2,3,4,5};
    for (int&c : fl1)  
        cout << c << " ";
    cout<<endl;
    fl1.remove_if([](int x){ return x > 3;});
    for (int&c : fl1)  
        cout << c << " ";
    cout<<endl;
    return 0; 
} 

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

#include <iostream> 
#include <vector> 
#include <forward_list>  

using namespace std; 
  
int main() 
{ 
    forward_list<int> fl1 = {1,7,8,9,10};
    forward_list<int> fl2 = {2,3,4,5,6};
    fl1.splice_after(fl1.begin(), fl2);
    for (int&c : fl1)  
        cout << c << " ";
    cout<<endl;
    return 0; 
} 

 

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.