12.9 — Pointers and const
Consider the following code snippet: int main() { int x { 5 }; int* ptr { &x }; // ptr is a normal (non-const) pointer int y { 6 }; ptr = &y; // we can point at another value *ptr = 7; // we can change the value at …
Consider the following code snippet: int main() { int x { 5 }; int* ptr { &x }; // ptr is a normal (non-const) pointer int y { 6 }; ptr = &y; // we can point at another value *ptr = 7; // we can change the value at …
The need for dynamic memory allocation C++ supports three basic types of memory allocation, of which you’ve already seen two. Static memory allocation happens for static and global variables. Memory for these types of variables is allocated once when your program is run and persists throughout the life of your …
The C-style array passing challenge The designers of the C language had a problem. Consider the following simple program: #include <iostream> void print(int val) { std::cout << val; } int main() { int x { 5 }; print(x); return 0; } When print(x) is called, the value of argument x …
Pointers are one of C++’s historical boogeymen, and a place where many aspiring C++ learners have gotten stuck. However, as you’ll see shortly, pointers are nothing to be scared of. In fact, pointers behave a lot like lvalue references. But before we explain that further, let’s do some setup. Related …
Many web hosts use CPanel, as it offers a fairly intuitive way for people to manage their accounts. CPanel comes with a file manager that is functional, but somewhat clunky. Although CPanel offers a mechanism for extracting archives (.zip and .gz), this mechanism has one major downside: when extracting .zip …
In lesson , we introduced C-style arrays, which allow us to define a sequential collection of elements: int testScore[30] {}; // an array of 30 ints, indices 0 through 29 In lesson , we defined a string as a collection of sequential characters (such as “Hello, world!”), and introduced C-style …
Last week I recieved an exciting email — an invitation to help test upcoming Online PvP RPG Fury. Consequently, I spent a large part of this past weekend playing, testing, and forming an initial impression of Fury. Fury just entered the closed beta stage this past weekend, so keep in …
Consider a game like Tic-tac-toe. The standard board for this game is a 3×3 grid, with players taking turns placing ‘X’ and ‘O’ symbols. The first to get three symbols in a row wins. While you could store the board data as 9 individual variables, we know that when you …
To recap the process needed to use a library: Once per library: Acquire the library. Download it from the website or via a package manager. Install the library. Unzip it to a directory or install it via a package manager. Tell the compiler where to look for the header file(s) …
Sorting an array is the process of arranging all of the elements in the array in a particular order. There are many different cases in which sorting an array can be useful. For example, your email program generally displays emails in order of time received, because more recent emails are …