

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 6
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
Remember, pointers are just an address (read: value) that tells the computer where to look for other values. Just like how the address to your house is not actually your house, but points you to where your house is.
Declare a pointer to an integer:
// declares `pointer_to_something` as a pointer to an int
int *pointer_to_something;
Get the address of a variable:
int meaning_of_life = 42;
int *pointer_to_mol = &meaning_of_life;
// pointer_to_mol now holds the address of meaning_of_life
Oftentimes we have a pointer, but we want to get access to the data that it points to. Not the address itself, but the value stored at that address.
We can use an asterisk (*) to do it. The * operator dereferences a pointer.
int meaning_of_life = 42;
int *pointer_to_mol = &meaning_of_life;
int value_at_pointer = *pointer_to_mol;
// value_at_pointer = 42
It can be a touch confusing, but remember that the asterisk symbol is used for two different things:
int *pointer_to_thing;int value = *pointer_to_thing; (retrieving the value) or *pointer_to_thing = 20; (modifying the value)Fix the change_filetype function (both in the .c and .h files). It should copy the struct from the pointer, update the copy, and leave the original unchanged.