C Pointers

Intermediate
19 min read
Updated: Nov 2026
1 example
13 guides

Definition and Usage

A pointer is a variable that stores a memory address. Pointers let functions modify caller data, walk through arrays and strings, build dynamic data structures, and call functions indirectly. This section covers address-of (`&`) and **dereference (*), pointer arithmetic, pointers and arrays, strings, function pointers, `void` and `NULL` pointers, and dangling pointers**.

Read declarations from the name outward.

int *p is "p is a pointer to int". int *arr[3] is an array of three pointers, while int (*fp)(int) is a pointer to a function taking an int.

Learning Path

Work through the stages in order, or jump to a topic from the index below (13 tutorials).

C Examples

A quick taste of pointers. Compile with gcc file.c -std=c11 -Wall -o out.

Example 1 — Change a variable through a pointer

Take an address, store it, then write through it.

C
#include <stdio.h>

int main(void) {
    int x = 42;
    int *p = &x;

    printf("x = %d, *p = %d\n", x, *p);
    *p = 50;
    printf("x is now %d\n", x);
    return 0;
}

How It Works

  1. &x is the address of x, stored in p.
  2. *p reads the value at that address.
  3. Assigning to *p changes x itself.

C Pointers Topics

Every guide in this section with a one-line summary (13 tutorials).

Pointer fundamentals

3 tutorials

Addresses, dereferencing, and moving through memory.

TopicDescriptionTutorial
Pointer basicsDeclare pointers and understand what they store.Try it
Address and dereferenceUse & to get an address and * to follow it.Try it
Pointer arithmeticAdd, subtract, and compare pointers to move through memory.Try it

Pointers with data

6 tutorials

Use pointers with arrays, strings, and functions.

TopicDescriptionTutorial
Pointers and arraysSee why an array name acts like a pointer and where the two differ.Try it
Pointers and stringsWalk and modify C strings with char pointers.Try it
Pointers and functionsPass pointers into functions and return pointers from them.Try it
Array of pointersStore several pointers in an array, such as a list of strings.Try it
Pointer to pointerUse double pointers to change a pointer from inside a function.Try it
Function pointersStore and call functions through pointers, tables, and callbacks.Try it

Safety and special pointers

4 tutorials

void, NULL, dangling pointers, and const correctness.

TopicDescriptionTutorial
void pointersHold the address of any object with void *, then cast to use it.Try it
NULL pointersUse NULL to mean "points to nothing" and check it before dereferencing.Try it
Dangling pointersAvoid pointers to memory that no longer exists.Try it
const and pointersTell const pointer-to-const, const pointer, and both apart.Try it

Edge Cases & Pitfalls

Common mistakes when learning pointers in C.

wild

Uninitialized pointers

A pointer that has not been assigned points to a random address. Initialize to a valid address or NULL.

null

Dereferencing NULL

Reading or writing through NULL crashes. Check before use.

dangle

Using freed memory

After free(p) or after a function returns, old addresses are invalid. Set pointers to NULL when done.

Key Takeaways

  • &: address of.
  • *: value at.
  • Valid: every pointer should point somewhere valid or be NULL.

One line: A pointer is a variable that stores a memory address.

Frequently Asked Questions

A pointer is a variable whose value is the memory address of another object. You declare it with * and read or write the target with the dereference operator *.
They add a layer of indirection and mistakes cause undefined behavior rather than clear errors. Practice with small programs and compile with warnings and AddressSanitizer.
Typically 8 bytes on 64-bit systems and 4 bytes on 32-bit systems, regardless of the pointed-to type.

Next: Pointer Basics

Declare pointers and understand what they store.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful