In Lesson 14 of Learn C With Me, we begin Chapter 12 — Manual Memory Allocation from Beej’s Guide to C Programming.
This time, we explore how C programs can request memory dynamically, work with that memory through pointers, and release it when it’s no longer needed.
We cover:
- What manual memory allocation means
- The difference between automatic and dynamically allocated storage
- Introducing
malloc() - Allocating memory for integers and arrays
- Using
sizeofto calculate allocation sizes - Why
malloc()returns a pointer - Checking allocation failures against
NULL - Accessing dynamically allocated memory through pointers
- Using array notation with allocated memory
- Understanding the relationship between pointers and arrays
- Releasing allocated memory with
free() - Why accessing freed memory causes undefined behavior
- Understanding memory leaks
- Introducing
calloc() - The difference between
malloc()andcalloc() - Zero-initialized allocated memory
- Understanding allocation sizes and element counts
- A brief look at integer overflow in allocation calculations
- Revisiting pointer declarations and dereferencing
- Understanding memory addresses and pointer values
- How passing pointers to functions allows modification of original data
- A discussion about CPU registers and assembly language
One of the main challenges in this lesson is understanding how a pointer relates to the memory allocated by malloc(). We spend time experimenting with the examples, inspecting values, and revisiting earlier pointer concepts.
We also discuss why memory management is the programmer’s responsibility in C. Allocated memory must eventually be released, and using memory after freeing it is undefined behavior.
Later, we explore calloc() and how it differs from malloc(), especially when it comes to initialization and allocation size calculations.
The lesson also takes an extended detour back into pointer fundamentals, including addresses, dereferencing, and how pointers relate to the actual contents of memory. We even explore some assembly language concepts to better understand what’s happening at a lower level.
As usual, we read the book, experiment with code, ask questions, make mistakes, and work through difficult concepts together with help from the live chat.
This is Part One of Manual Memory Allocation. We’ll return to the remaining material in the next lesson.
This is an interactive, follow-along live course. I am learning C alongside you, so expect questions, mistakes, experiments and plenty of discussion. No passive watching here — participate in the chat and work through the examples with us.

