When we pass an array to a function, a pointer is actually passed.
When a vector is passed to a function, a copy of the vector is created. For example, we can see below program, changes made inside the function are not reflected outside because function has a copy.
The above style of passing might also take a lot of time in cases of large vectors. So it is a good idea to pass by reference.
10 20 30
If we do not want a function to modify a vector, we can pass it as a const reference.
This article is contributed by Kartik. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.