

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 9
click for more info
Not enough gems
Cost: 6 gems
1: Pointer-Pointers
incomplete
2: Array of Pointers
incomplete
3: Void Pointers
incomplete
4: Swapping Integers
incomplete
5: Swapping Strings
incomplete
6: Generic Swap
incomplete
This lesson's interactive features are locked, please to keep using them
Making an array of integers on the heap is pretty simple:
int *int_array = malloc(sizeof(int) * 3);
int_array[0] = 1;
int_array[1] = 2;
int_array[2] = 3;
But we can also make an array of pointers! It's quite common to do this in C, especially considering that strings are just pointers to chars:
char **string_array = malloc(sizeof(char *) * 3);
string_array[0] = "foo";
string_array[1] = "bar";
string_array[2] = "baz";
Sneklang, being a super-robust programming language toolchain, needs to represent "Tokens" – strings of text that represent Sneklang syntax, things like if, else and def. They're represented as structs, you can see the struct in exercise.h.
Take a look at create_token_pointer_array. It correctly allocates an array of token pointers on the heap, but notice that the addresses it's adding to each index are the addresses of the stack-allocated inputs.