title: Why does realloc create two different pointers?
body: <p>I have a pointer array named **lines, each line being 100 character long.</p>
  
  <p>And have a function which adds characters to any given line and reallocates the line if it's not big enough:</p>
  
  <pre><code>void add_letter(char *line, int pos, char letter) {
      if(strlen(line) % 100 == 0){
          line = realloc(line, sizeof(char) * strlen(line) + 100);
      }
      ...
  </code></pre>
  
  <p><code>add_letter</code> is called like this:</p>
  
  <pre><code>add_letter(lines[0], pos, ch);
  </code></pre>
  
  <p>line here is equal to <code>lines[0]</code>, and in the  second line, gdb returns <code>1</code> for <code>p line == lines[0]</code>.
  Here <code>line</code> and <code>lines[0]</code> are both in memory location <code>0x6465e0</code>.</p>
  
  <p>But after the <code>realloc</code> call, <code>line</code> becomes <code>0x648200</code>, but <code>lines[0]</code> stays in the same and becomes an <code>""</code> empty string.</p>
  
  <p>What causes <code>realloc</code> to act like this? Because of this reason, <code>strcat(line, newline)</code>, <code>newline</code> being the end result of addition doesn't work at the end of the function.</p>