Home Tutorials C Tutorial Pointers
Pointers

Pointers


Pointers in C

What is a Pointer?

A Pointer is a variable that stores the memory address of another variable rather than a direct value.

Every variable you create is stored in a specific location in your computer's RAM, identified by a unique hexadecimal address. Pointers allow you to "point" to that location and modify the data sitting there.

  • Address-of Operator (&): Used to get the memory address of a variable.
  • Dereference Operator (*): Used to access the value stored at the address held by the pointer.

Syntax

data_type *pointerName;

// Example:
int *ptr; // A pointer that can hold the address of an integer

Practical Example

Example: Storing and Accessing an Address

int val = 50;
int *ptr;

ptr = &val; // ptr now holds the address of val

printf("Address of val: %p\n", ptr);
printf("Value of val: %d\n", *ptr); // Dereferencing ptr to get 50

📍 The GPS Analogy

Think of a Variable as a House. The Value is the person living inside. A Pointer is a piece of paper with the House Address written on it. It isn't the person, but it tells you exactly where to find them!

Important: Always initialize your pointers. A pointer that doesn't point to a valid address is called a Wild Pointer and can cause your program to crash if you try to use it.
Example

🏋️ Test Yourself With Exercises

Take our quiz on Pointers to test your knowledge.

Browse Quizzes »