Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/Language/C++/Addresses.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ has_children: false
{{ page.title }}
======================

{: .warning }
This article is quite advanced and assumes you have an understanding of C++.
{: .warning } This article is quite advanced and assumes you have an understanding of C++.
If not, please refer to the [C++](/docs/Language/C++/C++.html) section of this book!

In C++, the ampersand (`&`) symbol is the address-of operator, used to obtain the memory address of a variable. The memory address represents the location in the computer's memory where the variable is stored.
Expand All @@ -24,6 +23,8 @@ int value = *somePtr; // Retrieves the value stored at the memory address

The memory address is typically represented as a hexadecimal number.

#### Example

```cpp
#include <iostream>

Expand Down
7 changes: 3 additions & 4 deletions docs/Language/C++/ConstantPointerToConstant.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ has_children: false
{{ page.title }}
======================

{: .warning }
This article is quite advanced and assumes you have an understanding of C++.
{: .warning } This article is quite advanced and assumes you have an understanding of C++.
If not, please refer to the [C++](/docs/Language/C++/C++.html) section of this book!

A const pointer to const in C++ is a pointer that cannot be used to modify the value it points to, and the pointer itself cannot be reassigned to point to a different memory location. This provides a high level of const-correctness and is often used to indicate that both the pointer and the pointed-to value are constant.
Constant Pointers To Constants are a C++ pointer type that cannot be used to modify the value it points to, and the pointer itself cannot be reassigned to point to a different memory location. This provides a high level of const-correctness and is often used to indicate that both the pointer and the pointed-to value are constant.

```cpp
int someVar = 69;
Expand All @@ -34,7 +33,7 @@ It offers several benefits:
- When used in function parameters or class member functions, const pointers to const contribute to designing safer interfaces by indicating that the function/method will not modify the input data.
- Allows the compiler to make certain optimizations based on the const-correctness, potentially leading to more efficient code.

#### Usage Example
#### Example

```cpp
#include <iostream>
Expand Down
7 changes: 3 additions & 4 deletions docs/Language/C++/ConstantPointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ has_children: false
{{ page.title }}
======================

{: .warning }
This article is quite advanced and assumes you have an understanding of C++.
{: .warning } This article is quite advanced and assumes you have an understanding of C++.
If not, please refer to the [C++](/docs/Language/C++/C++.html) section of this book!

Const Pointers are quite straightforward - as with any other standard `const` variable in C++, it's a type of pointer that cannot be reassigned to point to a different memory address. It still allows read-write access to the pointed-to variable though!
Constant Pointers are quite straightforward - as with any other standard `const` variable in C++, it's a type of pointer that cannot be reassigned to point to a different memory address. It still allows read-write access to the pointed-to variable though!

```cpp
int someVar = 69;
Expand All @@ -33,7 +32,7 @@ It offers a few benefits:
- When used in function parameters or class member functions, const pointers contribute to designing safer interfaces by indicating that the function/method will not modify the pointer itself, offering const-correctness.
- Allows the compiler to make certain optimizations based on const-correctness, potentially leading to more efficient code.

#### Example Usage
#### Example

```cpp
#include <iostream>
Expand Down
3 changes: 1 addition & 2 deletions docs/Language/C++/Dereferencing.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ has_children: false
{{ page.title }}
======================

{: .warning }
This article is quite advanced and assumes you have an understanding of C++.
{: .warning } This article is quite advanced and assumes you have an understanding of C++.
If not, please refer to the [C++](/docs/Language/C++/C++.html) section of this book!

The dereference operator (`*`) is used to access the value at the memory address stored in a pointer.
Expand Down
3 changes: 1 addition & 2 deletions docs/Language/C++/MemberPointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ has_children: false
{{ page.title }}
======================

{: .warning }
This article is quite advanced and assumes you have an understanding of C++.
{: .warning } This article is quite advanced and assumes you have an understanding of C++.
If not, please refer to the [C++](/docs/Language/C++/C++.html) section of this book!

Member Pointers are traditional pointers that point to class or struct members.
Expand Down
4 changes: 2 additions & 2 deletions docs/Language/C++/MultilevelPointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Multilevel pointers refer to pointers that point to other pointers, forming a ch

While these types of pointers provide flexibility, they can make code more error-prone. Keeping track of each level of indirection and managing memory properly is crucial to avoid memory leaks and undefined behavior. In addition to this, there are many complaints among developers that multilevel pointers drastically ireduce code readability.

#### Usage
#### Multilevel Pointer Examples

A regular pointer is a single-level pointer, pointing directly to a variable.

Expand Down Expand Up @@ -95,7 +95,7 @@ Multilevel pointers are also useful for handling arrays of pointers or for guard
> "There are readability concerns for sure. As for it being a guard, _kind of, I guess?_ The main issue is that the API's are templated, so it is already kind of expecting to return a `float*` or `int*` or whatever, which, in my opinion is totally legit - guarding, like you said. But, if the array is an array of points to BEGIN with, you're left with the `**` nonsense."
> _- [@Tom Shinton](www.tomshinton.com), Discussion about Multilevel Pointer use-cases._

#### Example Usage
#### Example

```cpp
#include <iostream>
Expand Down
5 changes: 2 additions & 3 deletions docs/Language/C++/NullPointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ has_children: false
{{ page.title }}
======================

{: .warning }
This article is quite advanced and assumes you have an understanding of C++.
{: .warning } This article is quite advanced and assumes you have an understanding of C++.
If not, please refer to the [C++](/docs/Language/C++/C++.html) section of this book!

`nullptr` is a keyword introduced in C++11 to represent a pointer that points to... well, nothing - It's a constant that can be assigned to any pointer type to indicate that the pointer is not pointing to a valid memory location. Before the introduction of `nullptr`, programmers often used the integer constant `0` or the macro `NULL` to represent a null pointer. However, using `nullptr` is preferred.
Expand All @@ -26,7 +25,7 @@ Note that a `nullptr` is not implicitly convertible to integral types, which hel

Checking or Guarding for invalid pointers frequently in your code is good practice, especially when writing critical programs.

#### Example Usage
#### Example

```cpp
class SomeClass
Expand Down
2 changes: 1 addition & 1 deletion docs/Language/C++/PointerToConstant.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ It offers a few benefits:
- When used in function parameters or class member functions, a pointer to const indicates that the function/method will not modify the input data, offering safer interfaces.
- Allows the compiler to make certain optimizations based on const-correctness, potentially leading to more efficient code.

#### Example Usage
#### Example

```cpp
#include <iostream>
Expand Down
5 changes: 2 additions & 3 deletions docs/Language/C++/Pointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ has_children: false

## Pointers Overview

{: .warning }
This article is quite advanced and assumes you have an understanding of C++.
{: .warning } This article is quite advanced and assumes you have an understanding of C++.
If not, please refer to the [C++](/docs/Language/C++/C++.html) section of this book!

In C++, pointers are variables that store references to memory addresses of other variables. The data type of a pointer is the type of the variable it points to. They are powerful and performant due to their nature (as they tell the compiler where to look for data/objects in memory, rather than holding a copy of the data/object), but require careful handling to avoid issues like memory leaks and undefined behavior.

Imagine that pointers are like "signposts" that tell you where an object is in a box, rather than being a copy of the object - when there are several thousand objects floating around, the advantages are clear and can help to ensure operations occur on the correct object reference!

#### Usage Example
#### Example

```cpp
#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion docs/Language/C++/References.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ References offer some benefits, such as:
- References improve code readability by creating expressive and self-documenting code. The use of references indicates that the variable is being referenced or modified within a function.
- References are commonly used in operator overloading, allowing you to define custom behaviors for operators like +, -, etc.

#### Example usage
#### Example

```cpp
#include <iostream>
Expand Down
2 changes: 2 additions & 0 deletions docs/Language/C++/VoidPointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ void genericFunction(void* data, size_t size);

Void pointers do not provide type information, so improper casting can lead to runtime errors. It's essential to use them carefully and only when necessary, as they may make the code less readable and harder to maintain. In my example below, the type of void pointer is changed from an integer to a float, and even in this simple situation it can get quite difficult to follow.

#### Example

```cpp
#include <iostream>

Expand Down