LakshyaEducation.in

VEDIC MATHS Video Series
  • Home
  • Video Series
    • Vedic Maths Videos
    • Quantitative Aptitude Videos
    • Class 8 Maths Videos
    • Class 9 Maths Videos
    • Class 10 Maths Videos
  • Quiz & Solutions
  • Blog
  • Store
  • Login
  • Contact Us
  • Home
  • Topic
  • C++ Programming
  • Vector

C++ Programming

VECTOR MCQs

Total Questions : 10

Question 1.

Which is optional in the declaration of vector?


  1.    Type
  2.    Name
  3.    Vector
  4.    Number_of_elements
 Discuss Question
Answer is Option D. -> Number_of_elements

The number of elements is optional. An empty vector means, A vector that contains zero elements.

Question 2.

 Pick out the correct statement about vector.
a) vector<int> values (5)
b) vector values (5)
c) vector<int> (5)
d) None of the mentioned



  1.    Type
  2.    Name
  3.    Vector
  4.    Number_of_elements
 Discuss Question
Answer is Option D. -> Number_of_elements

Answer:a
Explanation:The syntax for declaring the vector element is vector<type> variable_name (number

_of_elements);

Question 3.


What is the output of this program?



1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
vector first;
7.
first.assign (7,100);
8.
vector::iterator it;
9.
it=first.begin()+1;
10.
int myints[] = {1776,7,4};
11.
cout
  1.    10
  2.    9
  3.    8
  4.    7
 Discuss Question
Answer is Option D. -> 7

In this program, We are finding the size of the vector elements and resizing it.
Output:
$ g++ vect3.cpp
$ a.out
7

Question 4.


What is the output of this program?



1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
vector myvector (5);
7.
int* p = myvector.data();
8.
*p = 10;
9.
++p;
10.
*p = 20;
11.
p[2] = 100;
12.
for (unsigned i = 0; i < myvector.size(); ++i)
13.
cout
  1.    10 20 0 100 0
  2.    10 20 0 100
  3.    10 20 0
  4.    10 20
 Discuss Question
Answer is Option A. -> 10 20 0 100 0

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

Question 5.


What is the output of this program?



1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
vector a (3, 0);
7.
vector b (5, 0);
8.
b = a;
9.
a = vector();
10.
cout
  1.    10
  2.    9
  3.    8
  4.    7
 Discuss Question
Answer is Option D. -> 7

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

Question 6.

In which type of storage location are the vector members stored?


  1.    Contiguous storage locations
  2.    Non-contiguous storage locations
  3.    Both a & b
  4.    None of the mentioned
 Discuss Question
Answer is Option A. -> Contiguous storage locations

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

Question 7.

What do vectors represent?


  1.    Static arrays
  2.    Dynamic arrays
  3.    Stack
  4.    Queue
 Discuss Question
Answer is Option B. -> Dynamic arrays

Vectors are sequence containers representing arrays that can change in size.

Question 8.

How many vector container properties are there in c++?


  1.    1
  2.    2
  3.    3
  4.    4
 Discuss Question
Answer is Option C. -> 3

There are three container properties in c++. They are sequence, Dynamic array and allocator-aware.

Question 9.


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
  1.    16
  2.    16 2
  3.    16 2 77
  4.    16 2 77 29
 Discuss Question
Answer is Option D. -> 16 2 77 29

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

Question 10.


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
  1.    500
  2.    600
  3.    700
  4.    Error
 Discuss Question
Answer is Option B. -> 600

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

  • Share on Facebook!
  • Share on Pinterest!

Sub Topics

  • Abstract Classes
  • Access Control
  • Argument Passing
  • Arrays
  • Booleans
  • C++ Concepts
  • Catching Exceptions
  • Character Types
  • Class Hierarchies And Abstract Classes
  • Class Hierarchies Introduction
  • Classes
  • Comments And Indentation
  • Complex Number Type
  • Constants
  • Constructors And Destructors
  • Container Design
  • Conversion Operators
  • Declaration
  • Default Arguments
  • Dereferencing
  • Derivation And Templates
  • Derived Classes
  • Design Of Class Hierarchies
  • Enumerations
  • Error Handling
  • Error Handling Alternatives
  • Essential Operators
  • Exception Specifications
  • Exceptions
  • Exceptions And Efficiency
  • Exceptions That Are Not Errors
  • Floating Point Types
  • Free Store
  • Friends
  • Function Call
  • Function Declarations
  • Function Templates
  • Functions
  • Grouping Of Exceptions
  • Header Files Usage
  • Increment And Decrement
  • Integer Types
  • Large Objects
  • Linkage
  • Macros
  • Modularization And Interfaces
  • Multiple Inheritance
  • Namespaces
  • Objects
  • Objects And Classes
  • Oops Concepts
  • Operator Functions
  • Operators
  • Overloaded Function Names
  • Pointer To Function
  • Pointer To Void
  • Pointers
  • Pointers Into Arrays
  • Pointers To Members
  • References
  • Resource Management
  • Run Time Type Information
  • Sequence Adapters
  • Sequences
  • Simple String Template
  • Sizes
  • Specialization
  • Standard Exceptions
  • Standard Library Design
  • Statements
  • String Class
  • Structures
  • Subscripting
  • Template Arguments To Specify Policy Usage
  • Types
  • Uncaught Exceptions
  • Unspecified Number Of Arguments
  • User Defined Types
  • Value Return
  • Vector
  • Void

Recent Posts

  • Ssc Exam Guide Book
  • Vedic Maths Faq
  • Is Ssc Difficult Than Upsc?
  • Quantitative Aptitude Faqs
  • Sail E0 Results 2022
  • Sail E0 Exam Results Cancelled - Exam Will Be Rescheduled
  • Best Ssc Exam For Girls

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....

Topics

Computer Aptitude
SAIL Junior Officer (E-0)
10th Grade
11th Grade
12th Grade
4th Grade
5th Grade
6th Grade
7th Grade
8th Grade
9th Grade
NCERT
Cat
Commerce
Computer Science
Engineering
English
General Knowledge
Ias
Management
Quantitative Aptitude
Reasoning Aptitude
General Studies (Finance And Economics)
Vedic Maths
Analytical Instrumentation
Biochemistry
Bioinformatics
Biology
Biotechnology
Bitsat
Business Statistics
C Programming
C++ Programming
Cell Biology
Chemistry
Cost Accounting
Drug And Pharmaceutical Biotechnology
Electrical Measurement And Instrumentation
Environment Management
Environmental Biotechnology
Enzyme Technology
Financial Management And Financial Markets
Gate
General Science
Geography
Heat Transfer
History And National Movements
Human Anatomy And Physiology
Human And Cultural Diversity
Human Resource Management
Indian Economy
Indian Geography
Indian History
Indian Polity
Instrumentation Transducers
International Relations
Life Sciences
Marketing And Marketing Management
Mass Transfer
Mechanics Of Materials
Microbiology
Neet
Professional Communication
Renewable Energy
Sociology
Surveying
Total Quality Management
Uidai Aadhaar Supervisor Certification
Virology
LakshyaEducation.in
Lakshya Education
Bhilai,Chattisgarh,India
Email: admin@lakshyaeducation.in Phone: 07893519977 (WhatsApp)

Quick Links

  • Vedic Maths
  • Quantitative Aptitude
  • Class – IX Maths
  • Class – X Maths
  • Blog

Our Services

  • About us
  • Privacy
  • TOS
  • Refund / Cancellation
  • Contact
  • Affiliate Program
  • Copyright © 2022 All Right Reserved | Lakshya Education     ( )
    Login / Register

    Your Account will be created automatically when you click the below Google or Facebook Login Button.
    •   Login With Facebook
    •  Login With Google
     Login With Email/Password