Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The reason for that is that <code>std::cout</code> will treat a <code>char *</code> as a pointer to (the first character of) a C-style string and print it as such. If you want the <em>address</em> instead, you can just cast it to a pointer that <em>isn't</em> treated that way, something like:</p> <pre><code>cout &lt;&lt; (void *) terry; </code></pre> <p>(or use the <code>const void *</code> cast if you're worried about casting away constness, something that's not an issue in this particular case).</p> <hr> <p>If you're more of a purist than pragmatist, you can also use the C++ <code>static_cast</code>, along the lines of:</p> <pre><code>cout &lt;&lt; static_cast &lt;const void *&gt; (terry); </code></pre> <p>though it's unnecessary in this particular case, the cast to a <code>void *</code> will work fine. The following sample code shows all these options in action:</p> <pre><code>#include &lt;iostream&gt; int main (void) { const char *terry = "hello"; std::cout &lt;&lt; terry &lt;&lt; '\n'; std::cout &lt;&lt; (void *) terry &lt;&lt; '\n'; std::cout &lt;&lt; (const void *) terry &lt;&lt; '\n'; std::cout &lt;&lt; static_cast&lt;const void *&gt; (terry) &lt;&lt; '\n'; return 0; } </code></pre> <p>outputting (the address may be different in your environment):</p> <pre><code>hello 0x8048870 0x8048870 0x8048870 </code></pre> <p>Note that, when using the <code>static_cast</code>, you should ensure you don't try to cast away the constness with <code>static_cast &lt;void *&gt;</code> (that's what <code>const_cast</code> is for). This is one of the checks done by the newer C++ casts and the old-style cast does not have this limitation.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload