Why does this compile? (unsigned char *thing = (unsigned char *) "YELLOW SUBMARINE";) : <p>I'm struggling to understand why this line of code makes sense:</p>

<pre class="lang-cpp prettyprint-override"><code>unsigned char *thing = (unsigned char *)"YELLOW SUBMARINE";
</code></pre>

<p>An <code>unsigned char</code> holds one byte of data (i.e. 'Y') so an <code>unsigned char*</code> should be a pointer to that single byte of data. </p>

<p>If I try to put more than one character inside, the compiler should, in my thinking, get angry. Yet it doesn't mind that I'm putting 16 bytes here and telling the compiler I'm only pointing to a single <code>unsigned char</code>. Could someone please explain?</p>

<p>My thinking was that the compiler would allocate memory for one <code>unsigned char</code>, then write the whole string into it, overwriting adjacent memory and causing havoc. Yet I'm able to correctly dereference this pointer later on and retrieve the whole string, so there doesn't seem to be a problem.</p>

<p>Context: I'm trying to convert a string to something of this form (<code>unsigned char *</code>).</p>

<p>Thanks in advance!</p>
