7.2 — User-defined namespaces and the scope resolution operator

In lesson , we introduced the concept of naming collisions and namespaces. As a reminder, a naming collision occurs when two identical identifiers are introduced into the same scope, and the compiler can’t disambiguate which one to use. When this happens, compiler or linker will produce an error because they …

20.3 — Recursion

A recursive function in C++ is a function that calls itself. Here is an example of a poorly-written recursive function: #include <iostream> void countDown(int count) { std::cout << “push ” << count << ‘\n’; countDown(count-1); // countDown() calls itself recursively } int main() { countDown(5); return 0; } When countDown(5) …

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

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 …