x.x — Passing arguments by value
Author’s note Sorry for the inconvenience, but this lesson was deprecated when the rewrite of Chapter 9 was deployed on Jan 18, 2021. The content of this lesson has been integrated into lesson .
Author’s note Sorry for the inconvenience, but this lesson was deprecated when the rewrite of Chapter 9 was deployed on Jan 18, 2021. The content of this lesson has been integrated into lesson .
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 …
Author’s note Sorry for the inconvenience, but this lesson was deprecated when the rewrite of Chapter 9 was deployed on Jan 18, 2021. The content of this lesson has been integrated into lesson .
Member selection for structs and references to structs In lesson , we showed that you can use the member selection operator (.) to select a member from a struct object: #include <iostream> struct Employee { int id {}; int age {}; double wage {}; }; int main() { Employee joe …
In C++, a reference 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. This means we can use a reference to read or modify the object being referenced. Although references might seem silly, useless, …
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 …