- 01Getting Started
- 02Your First Output (cout)
- 03Variables and Types (int/double/string/bool)
- 04Conditionals (if statements)
- 05Loops (for statements)
- 06Writing a Function
- 07Working with Arrays
- 08Loops (while statements)
- 09Pointer Basics
- 10References
- 11Classes (Object-Oriented Programming)
- 12Constructors and Destructors
- 13Inheritance
- 14Using vector (the Standard Library)
- 15String Manipulation (string)
- 16Structs (struct)
- 17Error Handling (try/catch)
- 18The Ternary Operator
- 19The switch Statement
- 20[Applied] Build a Mini Inventory Management System
Pointer Basics
This lesson covers the basics of pointers, one of C++'s defining features. It's for anyone searching "C++ pointer basics."
A pointer is a variable that holds "where in memory another variable is stored" (its address). Declare one with type* variableName, get an address with &variableName, and access the value it points to with *pointer.
The example gets the address of int num = 10; with int* ptr = #, and displays its contents with *ptr.
A common early mistake is confusing & (getting an address) with * (getting the value it points to). It helps to picture a pointer as "a note holding a variable's address" โ that makes the difference between the address and the actual value easier to grasp.
In real projects, pointers let you pass large data to a function without copying it, making memory usage far more efficient. This tends to be the first real hurdle in learning C++, but it's a genuinely important concept.
๐งช This site can't compile or run C++ directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
