Intermediate C++ Game Programming Tutorial 2
In this two-part tutorial we learn all about pointers and pointer-related bullshits. Part one focuses on the basics--the most common pointer operations and the basic underlying mechanisms. In part two, we take a look at some less commonly-used but still important pointer operations (pointer arithmetic), as well as some other concepts related to pointers. This tutorial introduces a lot of new concepts and features, but is light on practical examples. In the following tutorials we will get more hands-on practice with pointers, but also make sure to experiment with them on your own after finishing Tutorial 2.
- Declaring pointers
- The addressof operator
- The dereference (indirection) operator
- The arrow (member of pointer) operator
- The indexing (subscript) operator
- Pointer Arithmetic (adjustment, comparison, and difference)
- Pointers to Pointers
- Pointer Reinterpretation
- C++ Style Casting
- Linked Lists
Video Timestamp Index
Bonus Video: Red Pill [Pointers]
This tutorial has another associated Red Pill video that explores the actual machine instructed emitted by the compiler for pointer-related operations. Like the previous Red Pill video, this material is strictly optional and is not required to proceed with the tutorials--it will not be referenced in future tutorials. Viewer discretion is advised. The video can be found: here.
Write a function called
sum which returns the sum of all elements of an
There are 2 assignments. Assignment 1: modify the
sum function so that it uses pointer arithmetic. Assignment 2: create a new function to reverse an array of
ints using pointer arithmetic techniques.
- At 24:30 in Part 1, Chili shows the calculation for indexing off of a pointer (
p) as B + 2 x 4 -> B, and then a memory store operation 69 -> int@[B], but in reality (optimized or not) the index calculation would be done as part of the memory access operation, so it would end up being something like 69 -> int@[B + 2 x 4].