Pointers

12.2 - Address-of operator


The address-of operator & takes the address of an object.

int target = 20;
// Sets p to the address of target.
int *p = ⌖

Note that the ampersand & is also used to declare a reference.

Task

  • Use the address-of operator to initialize p to the address of n.
    • int *p = &n;
#include <iostream> int main() { int n{42}; // Define p after this line. std::cout << *p << std::endl; }