Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is because a string (at least in C/C++) is not quite the same sort of thing as an integer. If we're talking C-style strings, then an array of them like</p> <pre><code>char* test[3] = { "foo", "bar", "baz" }; </code></pre> <p>what is actually happening under the hood is that "test" is an array of pointers, each of which point to the actual data where the characters are. Let's say, at random, that the "test" array starts at memory address 0x10000, and that pointers are four bytes long, then we might have</p> <pre><code>test[0] (memory location 0x10000) contains 0x10020 test[1] (memory location 0x10004) contains 0x10074 test[2] (memory location 0x10008) contains 0x10320 </code></pre> <p>Then we might look at the memory locations around 0x10020, we would find the actual character data:</p> <pre><code>test[0][0] (memory location 0x10020) contains 'f' test[0][1] (memory location 0x10021) contains 'o' test[0][2] (memory location 0x10022) contains 'o' test[0][3] (memory location 0x10023) contains '\0' </code></pre> <p>And around memory location 0x10074</p> <pre><code>test[1][0] (memory location 0x10074) contains 'b' test[1][1] (memory location 0x10075) contains 'a' test[1][2] (memory location 0x10076) contains 'r' test[1][3] (memory location 0x10077) contains '\0' </code></pre> <p>With C++ std::string objects much the same thing is going on: the actual C++ string object doesn't "contain" the characters because, as you say, the strings are of variable length. What it actually contains is a pointer to the characters. (At least, it does in a simple implementation of std::string - in reality it has a more complicated structure to provide better memory use and performance).</p>
    singulars
    1. This table or related slice is empty.
    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