I'm a college student about to start an introductory C programming course, and I have no real coding experience yet. I've heard that pointers and memory can be especially challenging for beginners, so I'd like to build a basic understanding before the course begins. Could someone explain, in beginner-friendly terms, what memory is, how programs use it, how variables are stored, and what pointers actually do? I'm especially interested in understanding how memory is requested and released, and why incorrect pointer use can cause problems.
3 Answers
Think of memory as the space your program uses to store information while it runs. When you write `int x;`, C reserves enough space for an integer and gives that space the name `x`. Other types use different amounts of space, and an array such as `int values[20];` reserves room for 20 integers next to one another. Local variables are commonly stored in stack memory and are automatically discarded when their function ends. For dynamically allocated memory, you request space from the heap with something like `int *values = malloc(20 * sizeof(int));`. That memory remains available until you return it with `free(values)`, so forgetting to free it can cause a memory leak.
A pointer is a variable whose value is a memory address. In `int *p;`, `p` is intended to hold the address of an integer. The address-of operator gets a variable’s address, as in `p = &x`, while the dereference operator reads or changes the value stored at that address, as in `*p = 10`. Dynamically allocated arrays are accessed through a pointer to their first element, and `values[2]` refers to the third element. C does not automatically prevent you from accessing memory outside an array or using memory after it has been freed, so bounds and object lifetimes matter a lot.
You’re definitely not alone—many students find C difficult at first because it gives you direct control over memory. A beginner-friendly video series can be useful, especially when you’re just getting started, but try writing small programs alongside it instead of only watching. Books can also help: The C Programming Language is concise and classic, while C Programming: A Modern Approach, Head First C, and C Programming Absolute Beginner’s Guide are more approachable for many beginners.
I’m planning to start with a beginner video series. Would you suggest using that first, or should I work through one of the books instead?
You don’t need to understand every detail of memory before writing your first C program. Start with variables, basic types, conditionals, loops, functions, and arrays. Then practice pointers with tiny examples: print a variable’s value, print its address using `%p`, assign that address to a correctly typed pointer, and use `*pointer` to read or change the original value. Once that feels comfortable, move on to `malloc` and `free`. The main rules are to initialize pointers, use the correct type, stay within array bounds, and never dereference a null, uninitialized, or already-freed pointer.

So a variable gets a piece of memory for storing its value, while a pointer stores the address of that piece of memory. If dynamically allocated memory is freed, the old data should no longer be accessed because that space may be reused, right?