Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't quite get what you are trying to ask. In your example the <code>"hello world"</code> <strong>is</strong> stored in the read-write area, but the <em>pointer to it</em> isn't, since it wasn't declared as <code>const</code>.</p> <p><code>const char* string</code> means, this is a <em>mutable pointer</em> to an <em>constant string</em>.</p> <p>To cause the pointer being stored in the read-only area, too, you would have to declare it as <code>const</code>:</p> <pre><code>const char* const string = "hello world"; </code></pre> <hr> <p><strong>const</strong></p> <p>I general all modifiers in the C and C++ languages bind to the value to it's <em>left</em>. Only if there is nothing to the left, they apply to the next to their right. Hence these two are the same:</p> <pre><code>char const* str; // Bind const modifier to 'char'. const char* str; // Bind const modifier to 'char', since there is nothing to the left. </code></pre> <p>When looking at this, you need to be aware of that a pointer declaration consists of 2 "parts". The <em>type</em> the pointer points to, and the pointer <em>itself</em>.</p> <p>Modifiers like <code>const</code> or <code>volatile</code> can be applied to both of these parts:</p> <pre><code>char* const str; // A constant pointer, that points to a mutable char (array). </code></pre> <p>Here a few examples, how <code>const</code> affects variables:</p> <pre><code>char const* a = "foo"; *a = '\0'; // Error, the array pointed to is not mutable. a = "bar"; // Okay. char* const b = "foo"; *b = '\0'; // Okay. b = "bar"; // Error, the pointer is not mutable. </code></pre>
    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.
 

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