Questions and Answers
- How can the member functions in the container be accessed?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
The container manages the storage space for its elements and provides member functions to access them, either directly or through iterators which reference objects with similar properties to pointers.
- Which of the following type does the container should define?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Every container must define an iterator type. Iterators allow algorithms to iterate over the container’s contents.
- What is the output of this program?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> VectorData;
int add (0);
VectorData.push_back (50);
VectorData.push_back (150);
VectorData.push_back (200);
while (!VectorData.empty())
{
add += VectorData.back();
VectorData.pop_back();
}
cout << add << '\n';
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
In this program, We are forming a stack and adding the elements and We are finding the total number of elements that are in stack.
- What is the output of this program?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
unsigned int k;
vector<int> One;
vector<int> Two (3, 50);
vector<int> Three (Two.begin(), Two.end());
vector<int> Four (Three);
int Array[] = {10, 12, 71, 38};
vector<int> Five (Array, Array + sizeof(Array) / sizeof(int) );
for (vector<int> :: iterator it = Five.begin(); it != Five.end(); ++it)
cout << ' ' << *it;
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
In this program, We got the values and printing it by using the vector and we are contructing vectors.
- How many vector container properties are there in c++?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
There are three container properties in c++. They are sequence, Dynamic array and allocator-aware.