C++ memory questions
I'm trying to clear up a little bit of my beginner's confusion about how things are stored in memory.
Suppose I have the following code:
When I use gdb, I see that ptr1 contains an address ending in 07, and ptr2 contains an address ending in 1a. If I did my hex math correctly, that's 0x13 which is 19 bytes away. From this I gather that the stack is growing up. However, if buffer2 is sitting on top of buffer1 in the stack, and buffer2 is 10 bytes, shouldn't buffer2 be only 10 bytes away from the head of buffer1?
char *ptr1 = buffer1;
char *ptr2 = buffer2;
Then I thought about memory only being word addressable, so really buffer1 takes up 8 bytes because that makes two words, and buffer3 takes up 3 bytes because that makes three words. Where does this "extra" storage get filled up? And even so, how can the blocks be 19 bytes away because that doesn't divide evenly into words.
5 bytes + 10 bytes + 4 bytes + 4 bytes. Maybe one of the pointers was located between one of the buffers. Sounds odd, but it might be the compiler trying to rearrange the stack frame in order to make exploiting more difficult. Either case, 19 can be acquired through both arrays and size of one of the pointers.
What about word addressing?