Raw Pointers and the Address-of Operator
Declare pointers, take addresses with & and understand pointer types.
Raw Pointers and the Address-of Operator is a free C++ Academy lesson on CoddyKit. This is lesson 1 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the C++ Academy learning path, and your progress syncs across the web and the CoddyKit app. The C++ Academy course includes 4 lessons in total.
What is a Pointer?
A pointer holds the address of another object. It is a variable whose value is a memory location.
Declaring a Pointer
The pointer type is T*. Conventionally place the * with the type.
int x = 10;
int* p = &x; // p holds the address of x
std::cout << p; // prints an address
std::cout << *p; // prints 10The Address-of Operator
The unary & takes the address of a variable. The result type is T*.
int x = 42;
int* p = &x;The Dereference Operator
The unary * reads or writes the object a pointer points to.
*p = 100;
std::cout << x; // 100 (x changed through p)Null Pointers
A pointer that does not point anywhere should be set to nullptr. Dereferencing it is undefined behavior.
int* p = nullptr;
if (p == nullptr) {
std::cout << "no target\n";
}Pointers Are Numbers Under the Hood
An address is just an integer (often 64 bits). The pointer type tells the compiler how to interpret the bytes at that address.
Pointer to const vs const Pointer
Two independent positions for const:
int x = 1, y = 2;
const int* p1 = &x; // pointer to const int (cannot modify *p1)
int* const p2 = &x; // const pointer to int (cannot reseat)
const int* const p3 = &x; // bothPointer Size
All pointers have the same size on a given platform — typically 8 bytes on 64-bit systems. Even a char* is 64 bits wide.
Function Pointers
You can take the address of a function and call it through the pointer.
int square(int x) { return x * x; }
int (*fp)(int) = □
std::cout << fp(5); // 25Pointers to Members
A special syntax exists for pointers to class members. Rare in modern code — most callbacks use std::function or lambdas instead.
Why Pointers Matter
Pointers underpin:
- Dynamic memory (
new/deleteor smart pointers) - Optional references (nullable)
- Polymorphism (virtual dispatch through base pointers)
- Interop with C APIs
Quick Check
What does the expression &x evaluate to?
Recap
A pointer holds an address. Use & to get an address and * to read or write the target. nullptr is the safe null value. Pointers underpin dynamic memory, optional references, and polymorphism.
Learn C++ with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 51
- Lessons
- 203
Frequently Asked Questions
Is the “Raw Pointers and the Address-of Operator” lesson free?
Yes — any 3 lessons of the C++ Academy learning path, including “Raw Pointers and the Address-of Operator”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The C++ Academy course includes 4 lessons in total.
What will I learn in “Raw Pointers and the Address-of Operator”?
Declare pointers, take addresses with & and understand pointer types. You practise C++ Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C++ Academy?
No prior experience is required. C++ Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.
How long does the “Raw Pointers and the Address-of Operator” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C++ Academy lesson?
Yes. Every C++ Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Raw Pointers and the Address-of Operator
- Dereferencing and Pointer Arithmetic
- nullptr and Null Pointer Safety
- When to Use Pointers vs References