Const Reference in C++. In C++, there is a term called const correctness which is the practice of adding const when not modifying values. In C++, when we create temporary variables such as function parameters or the variable used for ranged base for loops, we create a copy of the value. This can be expensive for non primitive data types such as strings and vectors where we copy over every element in the collections. Therefore it is better to use a reference and if not modifying the values, a const reference. Because of how references are implemented, it is actually more efficient to just copy the primitive data types.
If you need to review these topics:
Functions: https://youtu.be/65PSQUdH5k0
Pass by Value vs Reference: https://youtu.be/77XcoXwoK2c
C++ Playlist:
https://www.youtube.com/playlist?list=PLnKe36F30Y4ZDNIOZ51sX25pWKQ1pkpTE
Github Repo for C++ Code:
https://github.com/ImKennyYip/cpp
Install C++ with VS Code:
https://youtu.be/DMWD7wfhgNY
Subscribe for more coding tutorials !