We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Array of Pointers

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";

Assignment

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.