Questions and Answers
- How many items are there in sequence container?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
There are five items in sequence container. They are array, vector, list, forward_list and dequeue.
- Which is optional in the declaration of vector?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
The number of elements is optional. An empty vector means, A vector that contains zero elements.
- Pick out the correct statement about vector.
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
The syntax for declaring the vector element is vector<type> variable_name (number_of_elements);
- What is the output of this program?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> VectorData (6);
int* ptr = VectorData.data();
*ptr = 30;
++ptr;
*ptr = 15;
ptr[2] = 150;
for (unsigned k = 0; k < VectorData.size(); ++k)
cout << ' ' << VectorData[k];
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
In this program, We are allocating the values to the vector and unallocated values are left as zero.
- What is the output of this program?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> Data;
Data.assign (5,50);
vector<int>::iterator iter;
iter=Data.begin()+1;
int Array[] = {1200,20,40};
cout << int (Data.size()) << '\n';
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
In this program, We are finding the size of the vector elements and resizing it.