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 — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C++ Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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.
Frequently asked questions
Is the “Raw Pointers and the Address-of Operator” lesson free?
Yes — the full text of “Raw Pointers and the Address-of Operator” is free to read here on the web, and the C++ Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C++ Academy course, upgrade to CoddyKit PRO.
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; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
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