Pointer Basics & Memory Addresses

🟡 Intermediate

📖 Definition

A pointer variable (T* ptr) holds the hexadecimal RAM address of another object. The address-of operator (&) retrieves an object's memory address, while the dereference operator (*ptr) accesses the value at that address.

💡 Code Example

#include <iostream>

int main() {
    int val = 42;
    int* ptr = &val; // Store address of val in ptr

    std::cout << "Value: " << val << "\n";
    std::cout << "Address (&val): " << ptr << "\n";
    std::cout << "Dereferenced (*ptr): " << *ptr << "\n";
    return 0;
}