title: C Pointer Arithmetic, moving around in memory
body: <p>In the code below how come doing <code>current-&gt;next = (char*) current + sizeof(Node);</code> works but doing <code>current-&gt;next = current + sizeof(Node);</code> does not work?</p>
  <p>I don't know why I have to cast 'current' to a char* instead of leaving it a Node* when they are both the same byte size on my system.</p>
  <pre><code>// on my system
  // sizeof(char*) is 4 bytes
  // sizeof(Node*) is 4 bytes
  </code></pre>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  int main() {
  
      typedef struct Node {
          int data;
          struct Node* next;
          struct Node* prev;
      } Node;
  
      void* heap = malloc(25 * sizeof(Node));
  
      Node* head = (Node*) heap;
      head-&gt;prev = NULL;
      Node* tail = (char*) head + (24 * sizeof(Node));
      tail-&gt;next = NULL;
      Node* current = head;
  
      int i = 0;
      while (current != NULL) {
          current-&gt;data = i;
          if (current != tail)
              current-&gt;next = (char*) current + sizeof(Node);
          if (current-&gt;next != NULL)
              current-&gt;next-&gt;prev = current;
          current = current-&gt;next;
          i++;
      }
  
      printf(&quot;\n&quot;);
  
      current = head;
      while (current != NULL) {
          printf(&quot;%d-&gt;&quot;, current-&gt;data);
          current = current-&gt;next;
      }
  
      return(0);
  }
  </code></pre>