Introduction
Pointers are one of the most important and most confusing topics in C++. Many students struggle with
pointers because they deal directly with memory. This guide explains pointers in a simple, exam-focused,
and beginner-friendly way, using clear explanations and examples.
This study guide is designed for IT, Computer Science, and Engineering students who want to
understand pointers clearly and confidently.
What Is a Pointer?
A pointer is a variable that stores the memory address of another variable, not the value itself.
Example:
int x = 10;
int* ptr = &x;
- x stores the value 10 - ptr stores the address of x - &x means "address of x"
Why Pointers Are Important
Pointers are used for: - Dynamic memory allocation - Arrays and strings - Passing variables efficiently to
functions - Data structures like linked lists and trees
Pointers frequently appear in exams and coding tests.
Declaring and Initializing Pointers
Syntax:
data_type* pointer_name;
Example:
1
, int a = 5;
int* p = &a;
Important notes: - * means "pointer to" - Always initialize pointers
Dereferencing a Pointer
Dereferencing means accessing the value stored at the address.
Example:
int a = 20;
int* p = &a;
cout << *p;
Output:
20
• p → address
• *p → value at that address
Pointer and Variable Relationship
Expression Meaning
p Address stored in pointer
&a Address of variable a
*p Value at the address
Null Pointers
A null pointer does not point to any memory location.
Example:
2