I have the following code
void foo()
{
char *a, *b;
int *c, *d;
a = (char*)malloc(1);
b = (char*)malloc(1);
c = (int*)malloc(4);
d = (int*)malloc(4);
*a = 10;
*b = 20;
*c = 30;
*d = 40;
}
Here is the gdb output:
13 a = (char*)malloc(1);
(gdb) n
14 b = (char*)malloc(1);
(gdb) n
15 c = (int*)malloc(4);
(gdb) n
16 d = (int*)malloc(4);
(gdb) n
17 *a = 10;
(gdb) n
18 *b = 20;
(gdb) n
19 *c = 30;
(gdb) n
20 *d = 40;
(gdb) n
21 }
(gdb) p a
$1 = 0x804b008 "\n"
(gdb) p b
$2 = 0x804b018 "\024"
(gdb) x/40b a
0x804b008: 10 0 0 0 0 0 0 0
0x804b010: 0 0 0 0 17 0 0 0
0x804b018: 20 0 0 0 0 0 0 0
0x804b020: 0 0 0 0 17 0 0 0
0x804b028: 30 0 0 0 0 0 0 0
(gdb)
Though a
and b
are both char pointers. Why is pointer to b
equal to a + 16
? Any reason for offsetting 16 bytes?