CPP

CPP

Sequences and Containers has 9 Questions

What kind of iteration does forward_list provide in C++?

Uni-directional
Bi-directional
Multi-directional
None of the mentioned
What does the size of the vector refers to in c++?

Size of vector
Type of vector
Number of elements
None of the mentioned
Subsequent elements are moved in terms of _____ when an element in inserted in vector?

Assignment Operator
Copy constructor
Both assignment operator and copy constructor
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         vector<int> myvector (3);
  7.         for (unsigned i = 0; i < myvector.size(); i++)
  8.         myvector.at(i) = i;
  9.         for (unsigned i = 0; i < myvector.size(); i++)
  10.         cout << ' ' << myvector.at(i);
  11.         return 0;
  12.     }

1 2 3
0 1 2
1 2 3 4
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         list<int> mylist;
  7.         list<int> :: iterator it1, it2;
  8.         for (int i = 1; i < 10; ++i) mylist.push_back(i * 1);
  9.             it1 = it2 = mylist.begin();
  10.         advance (it2, 6);
  11.         ++it1;
  12.         it1 = mylist.erase (it1);
  13.         it2 = mylist.erase (it2);
  14.         ++it1;
  15.         --it2;
  16.         mylist.erase (it1, it2);
  17.         for (it1 = mylist.begin(); it1 != mylist.end(); ++it1)
  18.             cout << ' ' << *it1;
  19.         return 0;
  20.     }

1 3 6
8 9
Both a & b
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         deque<int> mydeque;
  7.         int sum (0);
  8.         mydeque.push_back ( 10 );
  9.         mydeque.push_back ( 20 );
  10.         mydeque.push_back ( 30 );
  11.         while (!mydeque.empty())
  12.         {
  13.             sum += mydeque.back();
  14.             mydeque.pop_back();
  15.         }
  16.         cout << sum << '\n';
  17.         return 0;
  18.     }

10
20
30
60
What is the use of adapter in STL in c++?

To provide interface
To manipulate the data
To extract the data
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     #include  
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         unsigned int i;
  7.         deque<int> mydeque;
  8.         deque<int> :: iterator it;
  9.         mydeque.push_back ( 100 );
  10.         mydeque.push_back ( 200 );
  11.         mydeque.push_back ( 300 );
  12.         for (it = mydeque.begin(); it != mydeque.end(); ++it)
  13.             mydeque.clear();
  14.         cout << ' ' << *it;
  15.     }

100
200
300
None of the mentioned
Which is used to iterate over container?

Associated iterator type
Data type of objects
Return type of variables
None of the mentioned