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

Pointer Basics

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.

Syntax Review

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

New: Dereferencing Pointers

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:

  1. Declaring a pointer type: int *pointer_to_thing;
  2. Dereferencing a pointer value: int value = *pointer_to_thing; (retrieving the value) or *pointer_to_thing = 20; (modifying the value)

Assignment

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.