• Register
100 points
7 2
Welcome to Kodlogs, programming questions and answer website.

A vector is a sequence that represents arrays that is used to store data. A vector is flexible unlike an array that is static. A vector allows the user to change its elements based on what the function is designed to achieve. 
 

Example

1 (v.front)238567(v.back)

Here’s the syntax of how you can create a vector;

Vector<object_type> var_name


Example, 

#include<vector>
Int main()
{
Std::vector <int> _vector;

Answer of the question “Are vectors passed by reference?”


The syntax creates a blank vector that does not need size declaration which answers the question that vectors do not need a reference unlike arrays. C++ uses a semantic of pass by value, however since vectors are flexible, the programmer may choose to pass by reference which is dependent on the task the function intends to execute.  This can be done by making the vector a constant which will restrict the vector contents.  Also note that a reference is not a pointer in this case. 

In C++, when there’s a need to pass by reference, you have to use & operator  to address to the vector that needs to be referenced. Conclusively, vectors in C++ are passed by value however the user can reference to make the vector constant. 
Hope this helps.
100 points
7 2