C Pointers

C Pointers (Complete Tutorial: Beginner → Advanced)
Pointers are one of the most powerful and important concepts in C.
They allow direct memory access, efficient function calls, dynamic memory, and are heavily used in DSA, OS, Embedded systems, and interviews.
What is a Pointer?
A pointer is a variable that stores the address of another variable.
Example
a→ normal variable&a→ address ofap→ pointer storing address ofa*p→ value at that address (10)
Why Pointers Are Needed?
- Direct memory access
- Call by reference
- Efficient array & string handling
- Dynamic memory allocation
- Data structures (Linked List, Tree)
Pointer Declaration Syntax
Examples
Pointer Initialization
Never use uninitialized pointers
Dereferencing Pointer (* Operator)
-
*pgives value stored at address
Pointer and Address Example (Memory View)
| Expression | Meaning |
|---|---|
a | Value (10) |
&a | Address |
p | Address of a |
*p | Value at address (10) |
Pointer Arithmetic
- Pointer moves by size of data type
Pointers and Arrays (Very Important)
- Array name itself is a pointer to first element
Pointer to Pointer (**)
- Used in dynamic memory & 2D arrays
Call by Reference Using Pointer
- Original variable is modified
Pointers with Functions (Function Pointer Intro)
-
fpstores function address
NULL Pointer
- Points to nothing
- Used to avoid garbage access
Dangling Pointer
- Avoid accessing freed memory
Void Pointer (void *)
- Generic pointer
- Used in libraries (
malloc,qsort)
Pointers and Dynamic Memory (Preview)
- Heap memory management
Common Pointer Mistakes
- Uninitialized pointer
- Dereferencing NULL pointer
- Forgetting
& -
Memory leak (missingfree) - Confusing
*and&
Interview Questions (Must Prepare)
What is a pointer?
Difference between
*and&Pointer vs array
What is NULL pointer?
What is dangling pointer?
What is void pointer?
Call by value vs call by reference
Real-Life Use Cases
Dynamic memory allocation
Data structures (Linked List, Tree)
Embedded systems
OS kernels
Function callbacks
Summary
- Pointers store addresses
-
*→ value,&→ address - Essential for performance & system-level coding
- Backbone of DSA, OS, Embedded, Interviews
