12.2 — The stack and the heap

The memory that a program uses is typically divided into a few different areas, called segments: The code segment (also called a text segment), where the compiled program sits in memory. The code segment is typically read-only. The bss segment (also called the uninitialized data segment), where zero-initialized global and …

12.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 …

8.12 — 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 …

6.13 — Inline functions

Consider the case where you need to write some code to perform some discrete task, like reading input from the user, or outputting something to a file, or calculating a particular value. When implementing this code, you essentially have two options: Write the code as part of an existing function …

9.9 — 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 …

11.14 — 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 pointer …