I might not be fully understanding what's going on here, but when I allocate two segments of memory for two variables, the address difference between the two doesn't seem to account for the amount of space that I'm allocating.
Code:
int
main(int argc, char* argv[]) {
int *foo = malloc(4*sizeof(int));
int *bar = malloc(sizeof(int));
printf("foo: %X\n", (unsigned int) foo);
printf("bar: %X\n", (unsigned int) bar);
return 0;
}
Output:
Code:
foo: 100120
bar: 100130
Given that I'm allocating 4 x sizeof(int) for foo (16 bytes), and assuming that allocation is contiguous, I'm expecting there to be a separation of at least 16 between the output for foo and bar (i.e. 100120 and 100136). What am I missing? Thanks in advance!