C++ Programming
VECTOR MCQs
Total Questions : 10
The number of elements is optional. An empty vector means, A vector that contains zero elements.
Answer:a
Explanation:The syntax for declaring the vector element is vector<type> variable_name (number
_of_elements);
In this program, We are finding the size of the vector elements and resizing it.
Output:
$ g++ vect3.cpp
$ a.out
7
In this program, We are allocating the values to the vector and unallocated values are left as zero.
Output:
$ g++ vect4.cpp
$ a.out
10 20 0 100 0
Answer:a
Explanation:In this program, We are finding the size of the vector elements.
Output:
$ g++ vect2.cpp
$ a.out
Size of a 0
Size of b 3
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
Vectors are sequence containers representing arrays that can change in size.
There are three container properties in c++. They are sequence, Dynamic array and allocator-aware.
What is the output of this program?
1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
unsigned int i;
7.
vector first;
8.
vector second (4, 100);
9.
vector third (second.begin(), second.end());
10.
vector fourth (third);
11.
int myints[] = {16, 2, 77, 29};
12.
vector fifth (myints, myints + sizeof(myints) / sizeof(int) );
13.
for (vector :: iterator it = fifth.begin(); it != fifth.end(); ++it)
14.
cout
In this program, We got the values and printing it by using the vector and we are contructing vectors.
Output:
$ g++ vect.cpp
$ a.out
16 2 77 29
What is the output of this program?
1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
vector myvector;
7.
int sum (0);
8.
myvector.push_back (100);
9.
myvector.push_back (200);
10.
myvector.push_back (300);
11.
while (!myvector.empty())
12.
{
13.
sum += myvector.back();
14.
myvector.pop_back();
15.
}
16.
cout
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.
Output:
$ g++ vect1.cpp
$ a.out
600
Recent Questions
Q. The Value Engineering Technique In Which Experts Of The Same....
Q. If Transcription Should Not Be Carried Out Beyond The Insert....
Q. Buffalo Is To Leather As Llama Is To....?
Q. Choose The Correct Answer From The Given Options To Fill The....
Q. The Arithmetic Mean (average) Of The First 10 Whole Numbers ....
Q. Which Governor General Is Remembered For The Annulment Of Th....
Q. When The Voltage Across A Capacitor Is Tripled, The Stored C....
Q. My Mother Bakes Cakes.
Q. Log Mean Temperature Difference In Case Of Counter Flow Comp....
Q. Which Of The Following Is Not A Matter Of Local Government?
Q. Which Drugs Can Easily Pass The Placental Barrier?
Q. Which Of The Following Is Not A Benefit Of BLAST?
Q. A Part Of John's Salary Was Cut By The Government. What....
Q. The Swollen Part Of The Pistil Is Known As ________ .
Q. By Definition, Make A Map Is To Select Certain Features As R....
Q. Which Of The Following Is The Best Tube Material From Therma....
Q. If You Are Going To Use A Combination Of Three Or More AND A....
Q. (a) A Ball Is Dropped From A Height Of 30m. After Striking T....
Q. What Is The Approx. Value Of W, If W=(1.5)11, Given Log2 = 0....
Q. In The Following Questions, The Symbols $, ©, *, @ And # Ar....