title: C realloc not changing apparent size of character array
body: <p>When I run the below code, I get the given output.</p>
  
  <pre><code>#include &lt;stdio.h&gt; /* printf */
  #include &lt;stdlib.h&gt; /* malloc, realloc */
  
  int main()
  {
      char* characters = (char *) malloc(10 * sizeof(char));
      printf("Before: characters at %p, size=%lu\n", (void *) characters, sizeof(characters) / sizeof(characters[0]));
      char* temp = (char *) realloc(characters, 100);
      if (temp)
      {
          printf("After realloc, characters size = %lu, temp size = %lu\n", sizeof(characters) / sizeof(characters[0]), sizeof(temp) / sizeof(temp[0]));
          printf("After realloc, nums at %p, temp at %p\n", (void *) characters, (void *) temp);
          //characters = temp;
          free(temp);
      }
      free(characters);
  }
  
  /* Output:
  Before: characters at 0x107b00900, size=8
  After realloc, characters size = 8, temp size = 8
  After realloc, nums at 0x107b00900, temp at 0x107b00910
  test(3556) malloc: *** error for object 0x107b00900: pointer being freed was not allocated
  *** set a breakpoint in malloc_error_break to debug
  Abort trap: 6
  */
  </code></pre>
  
  <p>I'm trying to figure out what is malfunctioning.
  I think that malloc sets aside space for ten consecutive characters and gives me a pointer to the first element of that array, and I store that pointer in <code>characters</code>. I then print the size of <code>characters</code>, and I expect 10, but I get 8. That's the first weird thing. Then, I ask realloc to find a new spot in the heap, which has space for 100 consecutive characters and return to me a pointer to the first spot. I put that pointer into temp. When I print <code>temp</code>'s size, I get 8 (again), even though I expect 100. When I print the pointers to <code>characters</code> and <code>temp</code>, I get two different locations in the heap. Usually, I would then reassign the <code>characters</code> pointer to point to whatever <code>temp</code> is pointing to. Then I tried to free my pointers, and it told me that it couldn't free <code>0x107b00900</code>, the exact location <code>characters</code> is, because the object at that point wasn't <code>malloc</code>ed; however, I did <code>malloc</code> space for <code>characters</code>. Why is this happening? Am I misunderstanding the functionality of <code>malloc</code>, <code>realloc</code>, <code>sizeof</code>, or something else? Thank you for your help.</p>