20.1 — Function Pointers

In lesson , you learned that a pointer is a variable that holds the address of another variable. Function pointers are similar, except that instead of pointing to variables, they point to functions! Consider the following function: int foo() { return 5; } Identifier foo is the function’s name. But …

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 …