Pointer to a given memory address -C++

Yes, you can construct a pointer that refers to some arbitrary address in memory, by initialising the pointer with the address directly, instead of with an expression like &a:

int* ptr = (int*)0x1234ABCD;  // hex for convenience
std::cout << *ptr;

Be careful, though, as it is rare that you know such a memory address exactly.

The cast (int*) is required as no implicit conversion exists between int and int*.

Browse More Popular Posts

Leave a Comment