Cast pointer address to int
c++
Solution
You can use `reinterpret_cast`. An `int` is not guaranteed to be able to losslessly store a pointer though, so you should use the `std::intptr_t` type instead.
Problem
Beginner question: How can I take the adress of a pointer and save it as an int? Example: ``` int *ptr = xyz; int i = static_cast<int>(ptr); ``` So if ptr points to the memory adress 123, i should be 123. My compiler says it's an `error: invalid static_cast from type 'int*' to type 'int'`. Guess I am missing something but I don't know what.