root@coding-prodigies:~# โ–Š
// lesson 3 of 11 ยท 22 min

Pointers and manual memory management

โš‘ Report an issue with this lesson
int value = 42;
int *ptr = &value;
printf("%d\n", *ptr); // 42, dereferencing the pointer

int *numbers = malloc(5 * sizeof(int));
numbers[0] = 10;
free(numbers); // you are responsible for freeing what you allocate

Every malloc needs exactly one matching free. Forget it, and you leak memory; free it twice, or use it after freeing, and you get undefined behavior โ€” this is the exact category of bug that languages like Rust were designed to eliminate at compile time.

Try it yourself

Exercise: Use a pointer to double the value of x, then print x.
Expected output:
42
c
Output

      
    

Run your code and get it working before marking this lesson complete.

// that was the last free lesson

8 more lessons โ€” including Capstone project: a linked list library โ€” plus a certificate are waiting.

Unlock the full course โ€” $149.99