Friday, January 25, 2013

Variable in stack

I conducted experiment what happened in the memory when I created variable that is put on stack.

The system will leave 8 bytes empty for the next data that will be put on stack.

But the first variable that you create will be put on the bottom of the stack + 4 bytes empty

For example:
int main()
{
int a; // it is put on address 0x001CFA60.This is the bottom of the stack. 0x001CFA60 - 0x1CFA63 will be reserved for int a. And address 0x1CFA64 - 0x1CFA67 will be left empty

int b; // it will be put on address 0x1CFA54. From 0x1CFA54 - 0x1CFA57 will be reserved for the int b itself, from 0x1CFA58 - 1CFA5F will be empty. Then the next address is for the int a. Therefore, when creating variable, it will be put on above the previous variable + 8 bytes empty.
}

No comments:

Post a Comment