title: C++ - Inserting and Extracting Characters from an Integer Array
body: <p>For example:</p>
  
  <pre><code>char mem[100000];
  
  int reg[8];
  
  mem[36] = 'p';         // add char p to our 36th index of our char array
  
  reg[3] = (int)mem[36]; // store value of mem[36] into reg[3]
  </code></pre>
  
  <ul>
  <li><p>Now I want to print the char value at index 3 of that int array.</p></li>
  <li><p>So far my thought process has lead me to code such as this:</p>
  
  <p>char *c = (char*)reg[3]; </p>
  
  <p>cout &lt;&lt; *c &lt;&lt; endl;</p></li>
  </ul>
  
  <p>But I am still getting weird values and characters when trying to print it out.</p>
  
  <p>From my understanding, an integer is equal to 4 characters. Since a character is technically a byte and an integer is 4 bytes.</p>
  
  <p>So I am storing a character into my integer array as 4 bytes, but when I pull it out, there is garbage data since the character I inserted is only one byte compared to the index being 4 bytes in size.</p>