10.14 — Default arguments

A is a default value provided for a function parameter. For example: void print(int x, int y=10) // 10 is the default argument { std::cout << “x: ” << x << ‘\n’; std::cout << “y: ” << y << ‘\n’; } When making a function call, the caller can optionally …

12.10 — Pass by address

In prior lessons, we’ve covered two different ways to pass an argument to a function: pass by value () and pass by reference (). Here’s a sample program that shows a std::string object being passed by value and by reference: #include <iostream> #include <string> void printByValue(std::string val) // The function …

19.5 — Void pointers

The void pointer, also known as the generic pointer, is a special type of pointer that can be pointed at objects of any data type! A void pointer is declared like a normal pointer, using the void keyword as the pointer’s type: void* ptr {}; // ptr is a void …

12.3 — Lvalue references

In C++, a is an alias for an existing object. Once a reference has been defined, any operation on the reference is applied to the object being referenced. Key insight A reference is essentially identical to the object being referenced. This means we can use a reference to read or …