title: What happens when you cast a char * address to int * in C when the address is not word-aligned?
body: <p>I'm running this bit of code to understand pointers a little better.</p>
  
  <pre><code>void foo(void)
  {
      int a[4] = {0, 1, 2, 3};
  
      printf("a[0]:%d, a[1]:%d, a[2]:%d, a[3]:%d\n", a[0], a[1], a[2], a[3]);
  
      int *c;
  
      c = a + 1;
      c = (int *)((char*) c + 1);
      *c = 10;
  
      printf("c:%p, c+1:%p\n", c, c+1);
      printf("a:%p, a1:%p, a2:%p, a3:%p\n", a, a+1, a+2, a+3);
  
      printf("a[0]:%d, a[1]:%d, a[2]:%d, a[3]:%d\n", a[0], a[1], a[2], a[3]);
  
      printf("c[0]:%d, c[1]:%d\n", *c, *(c+1));
  
  }
  </code></pre>
  
  <p>The output I get is:</p>
  
  <pre><code>a[0]:0, a[1]:1, a[2]:2, a[3]:3
  c:0xbfca1515, c+1:0xbfca1519
  a:0xbfca1510, a1:0xbfca1514, a2:0xbfca1518, a3:0xbfca151c
  a[0]:0, a[1]:2561, a[2]:0, a[3]:3
  c[0]:10, c[1]:50331648
  </code></pre>
  
  <p>Could someone please explain how a[1] is now 2561?</p>
  
  <p>I understand that when we do this:</p>
  
  <pre><code>c = (int *) ((char *) c + 1);
  </code></pre>
  
  <p>c is now pointing to the 4 bytes following the first byte of a[1].</p>
  
  <p>But how did a[1] end up with 2561?</p>
  
  <p>I'm guessing this has to do with endianness?</p>