Coding/Learn/c/c pointers and memory addresses
C Foundational Course
01.Introduction, Compilation Pipeline & Syntax
02.Variables, Primitives & Explicit Type Casting
03.Operators, Precedence & Booleans (<stdbool.h>)
04.Control Flow: If-Else, Ternary & Switch
05.Loops (For, While, Do-While) & Jump Statements
06.Contiguous Arrays & Multi-Dimensional Matrices
07.Null-Terminated Strings & <string.h>
08.User Input, scanf & fgets Buffer Safety
09.Pointers, Memory Addresses & Dereferencing
10.Functions, Prototypes & Pass-by-Pointer
11.11. Recursion & High-Speed Function Pointers
12.File Streams: Create, Write & Read (fopen/fclose)
13.Structures, Unions & typedef Aliasing
14.Memory Word Alignment & Struct Padding
15.Enums & Bitwise Manipulation (Flags & Masks)
16.Dynamic Memory: malloc, calloc, realloc & free
17.Defensive Error Handling, errno & Assertions
18.Preprocessor Macros & Storage Classes
19.Fixed-Width Types (stdint.h), Math & Time (<time.h>)
20.Capstone: High-Performance In-Memory Key-Value Engine
Course Certificate0%

Complete all lessons to earn

LearnPointers, Memory Addresses & Dereferencing
9 / 20 0%
Lesson 09 of 20
6 mins read

Pointers, Memory Addresses & Dereferencing

PreviousNext Lesson
In Plain English

A pointer in C is a variable storing the physical memory address of another variable. The address-of operator (&) extracts an address, the dereference operator (*) accesses/mutates the target value, and pointer arithmetic (ptr + i) steps through memory in sizeof(Type) chunks.

The Mental Model

"A variable is a house holding furniture (data); a pointer is a piece of paper with the street address of that house written on it."

Deep Dive: How It Works

Address-of (&): Evaluates to the memory address where a variable lives in RAM.

Dereference (*): Accesses the memory cell referenced by the pointer to read or write data.

Pointer Arithmetic: Adding 1 to int* advances the address by 4 bytes.

Syntax Blueprint

int val = 100;
int *ptr = &val;
*ptr += 50; // val is now 150

Store address in pointer variable and dereference with * to mutate in place.

PointCore Rules to Remember

Point star
Physical Address: Pointers store actual 64-bit RAM memory locations.
Point star
Direct Mutation: Dereferencing (*ptr) allows remote modification of variables across scopes.
Point star
NULL Initialization: Always initialize unassigned pointers to NULL to prevent reading wild memory.

Common Beginner Traps & How to Fix Them

Mistake:Dereferencing an uninitialized or NULL pointer: int *p; *p = 10;.

Why it happens: p contains random garbage stack bits; writing to it causes an OS segmentation fault (SIGSEGV).

How to fix: Always assign pointers to a valid address (&var) or allocate heap memory before dereferencing.

Pro Tip: Use pointer arithmetic (*(arr + i)) to traverse high-performance contiguous buffers without array indexing overhead.

Live Interactive Example

Hit Run Code to see it live
Pointer Mutation
C11 / GCC 9.2
1
2
3
4
5
6
7
8
9
10
Output Console
Click "Run Code" to view the rendered output.
How it works: *ptr += 50 modifies the memory location of value directly.

Your Turn: Micro Challenge

No pressure! Edit the starter code below and test your solution with instant feedback.

Micro Exercise

Print Value via Pointer Dereference

  • PointPrint "Dereferenced: %d\n" accessing value through *ptr.
1
2
3
4
5
6
7
8
9
10
11
12
Sandbox Output
Click "Run & Check" to test your solution.

Finished reading and practicing?

Mark this lesson as completed to update your course progress.

PreviousNext Lesson
Overview100 SheetLearnCertificates