C++ Const Reference
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
Install C++ with VS Code:
https://youtu.be/DMWD7wfhgNY
Subscribe for more coding tutorials 😄!
Other Videos By Kenny Yip Coding
2024-08-19 | Enums in C++ |
2024-08-14 | Global Variables in C++ |
2024-07-29 | Code Memory Card Game in Java |
2024-06-25 | Code Space Invaders in Java |
2024-06-05 | Code Google Chrome Dinosaur Game in Java |
2024-05-13 | Code Tic Tac Toe in Python |
2024-04-25 | C++ Recursion with Vectors |
2024-04-24 | Recursion in C++ |
2024-04-23 | Functions in C++ Practice Problems |
2024-04-22 | C++ Templates and Generics Functions |
2024-04-17 | C++ Const Reference |
2024-04-16 | C++ Function Overloading |
2024-04-15 | C++ Functions Pass by Value or Reference |
2024-04-08 | C++ Functions |
2024-03-27 | Pointers to Pointers C++ |
2024-03-26 | C++ Dynamic Arrays vs Dynamically Allocated Arrays |
2024-03-25 | C++ Dynamic Arrays (Dynamically Allocated Array) |
2024-03-20 | Dynamic Memory Allocation in C++ |
2024-03-19 | C++ Pointers and Arrays |
2024-03-18 | C++ Null Pointers |
2024-03-14 | References in C++ |