Questions and Answers
- What is the output of this program?
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> FirstData (4, 2);
vector<int> SecondData (6, 5);
SecondData = FirstData;
FirstData = vector<int>();
cout << "Size of First Data " << int(FirstData.size()) << '\n';
cout << "Size of Second Data " << int(SecondData.size()) << '\n';
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
In this program, We are finding the size of the vector elements.
- 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.
- In which type of storage location are the vector members stored?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Vectors use contiguous storage locations for their elements, which means that their elements can also be accessed using offsets on regular pointers to its elements