

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Memory
incomplete
2: What Is an Address?
incomplete
3: Virtual Memory
incomplete
4: Pointers
incomplete
5: Why Pointers?
incomplete
6: Pointer Basics
incomplete
7: Pointers to Structs
incomplete
8: C Arrays
incomplete
9: Arrays As Pointers in C
incomplete
10: Multibyte Arrays
incomplete
11: Array Casting
incomplete
12: Pointer Size
incomplete
13: Arrays Decay to Pointers
incomplete
14: C Strings
incomplete
15: C String Library
incomplete
16: Forward Declaration
incomplete
17: Mutual Structs
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Before we talk about pointers, we should talk about variables and memory in general. Here are some useful (albeit hand-wavy) mental models:
Variables are human readable names that refer to some data in memory.
Memory is a big array of bytes, and data is stored in the array.
A variable is a human readable name that refers to an address in memory, which is an index into the big array of bytes. Here's a diagram:
In C, you can print the address of a variable by using the address-of-operator: &. Here's an example:
#include <stdio.h>
int main() {
int age = 37;
printf("The address of age is: %p\n", &age);
return 0;
}
// The address of age is: 0xfff8
The %p format specifier will format a pointer (memory address) to be printed.
The size_of_addr function accepts a long long (a potentially very large integer) as input and returns the size of its address.
There's a bug! Memory addresses in Sneklang should always be 4 bytes long...
Fix the function so that it returns the size of i's address, not value.