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 pointer …
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 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. Key insight A reference is essentially identical to the object being referenced. This means we can use a reference to read or …
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 …
Pointers and arrays are intrinsically related in C++. Array decay In a previous lesson, you learned how to define a fixed array: int array[5]{ 9, 7, 5, 3, 1 }; // declare a fixed array of 5 integers To us, the above is an array of 5 integers, but to …
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 …
In lesson , we defined a string as a collection of sequential characters, such as “Hello, world!”. Strings are the primary way in which we work with text in C++, and std::string makes working with strings in C++ easy. Modern C++ supports two different types of strings: std::string (as part …