What is a Pointer?
Part of the Logic & Flow section of Coddy's C journey — lesson 1 of 63.
Think of your computer's memory like a giant apartment building with thousands of rooms. Each room has a unique address, and each room can store one piece of data. When you create a variable in C, it gets assigned to one of these rooms.
A pointer is a special type of variable that doesn't store regular data like numbers or characters. Instead, it stores the address of another variable's memory location. Think of it like writing down someone's apartment number on a piece of paper - the paper doesn't contain the person, but it tells you exactly where to find them.
int age = 25; // This creates a variable 'age' in memory
int *ptr; // This creates a pointer that can store an addressIn this example, age is stored at some memory address (let's say room 1004), and ptr is a pointer variable that could store the address 1004 to "point to" the age variable.
Pointers are one of C's most powerful features because they allow you to directly work with memory addresses, making your programs more efficient and enabling advanced techniques like dynamic memory allocation and complex data structures.
Cheat sheet
A pointer is a variable that stores the memory address of another variable, rather than storing data directly.
To declare a pointer, use the * operator:
int age = 25; // Regular variable
int *ptr; // Pointer variable that can store an addressPointers allow direct memory manipulation and enable advanced programming techniques like dynamic memory allocation and complex data structures.
Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Logic & Flow
1Pointers Fundamentals
What is a Pointer?Declaring PointersThe Address-Of Operator (&)The Dereference Operator (*)NULL PointersRecap: Pointer Basics4Project: Simple Text Utility
Project OverviewCounting Characters2Pointers and Arrays
Array Names as PointersArray Elements - PointersPointer ArithmeticComparing PointersRecap: Pointer Array Traversal5Pointers and Functions
Pass-by-ValuePassing Pointers to FunctionsModifying Vars via PointersA Classic Example: SwapPassing Arrays to FunctionsRecap: Function Pointer Args8Structs and Pointers
Pointers to StructsThe Arrow Operator (->)Passing Structs by ValuePassing Struct PointersDynamic Allocation of StructsRecap: Modifying Struct - Ptr11Final Recap Challenges
Recap: Dynamic String ConcatRecap: Array of StructsRecap: Word Frequency Counter3Character Arrays and Strings
Strings as char ArraysThe Null TerminatorString Input with scanfUsing strlen()Using strcpy()Using strcat()Using strcmp()Recap: Basic String Functions