Every variable lives at an address in memory. A pointer stores that address:
int x = 42;
int* p = &x; // p holds the address of x
// & means "address of"
cout << x; // 42 (the value)
cout << &x; // 0x... (the address)
cout << p; // same address
cout << *p; // 42 (* means "dereference: read value at that address")
int n = 10;
int* ptr = &n;
*ptr = 99; // changes n!
cout << n; // 99
int* p = nullptr; // points to nothing
if (p != nullptr) { // always check before dereferencing!
cout << *p;
}
Write tripleInPlace(int* p) that multiplies the value at the pointer by 3.
After tripleInPlace(&n) where n=4, n should be 12.
Click "Run" to execute your code.