Casting pointers without runtime checks

The reinterpret_cast operator allows pointers to one type to be converted to pointers of another type, and it can convert from a pointer to an integer and an integer to a pointer:

    double pi = 3.1415;     int i = reinterpret_cast<int>(&pi);     cout << hex << i << endl;

Unlike static_cast, this operator always involves a pointer: converting between pointers, converting from a pointer to an integral type, or converting from an integral type to a pointer. In this example, a pointer to a double variable is converted to an int and the value printed to the console. In effect, this prints out the memory address of the variable.

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.