The right way of using reinterpret_cast
<p>I would like to know the right way of using reinterpret_cast. I have a scenario wherein I have to save an address (say 0x1122) of type uint64_t using a void ** pointer (see example code below). All the three ways of doing so seem to work. What is the difference between them? Is one of them actually wrong? Also, what is the best way of doing this? Thanks!</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;cstdint&gt;

using std::cout;
using std::endl;

int main()
{
    void **localAddr;
    void *mem;
    localAddr = &amp;mem;
    // The above three lines is the setup that I have to work with.
    // I can't change that. Given this setup, I need to assign an
    // address 0x1122 to mem using localAddr.

    // Method 1
    *localAddr = reinterpret_cast&lt;uint64_t*&gt;(0x1122);
    cout &lt;&lt; mem &lt;&lt; endl; // Prints 0x1122

    // Method 2
    *(reinterpret_cast&lt;uint64_t*&gt;(localAddr)) = 0x1122;
    cout &lt;&lt; mem &lt;&lt; endl; // Prints 0x1122

    // Method 3
    *localAddr = reinterpret_cast&lt;void*&gt;(0x1122);
    cout &lt;&lt; mem &lt;&lt; endl; // Prints 0x1122

    return 0;
}
</code></pre>
