I'm running this bit of code to understand pointers a little better.
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));
}
The output I get is:
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
Could someone please explain how a[1] is now 2561?
I understand that when we do this:
c = (int *) ((char *) c + 1);
c is now pointing to the 4 bytes following the first byte of a[1].
But how did a[1] end up with 2561?
I'm guessing this has to do with endianness?