I'm very curious of the stack memory organization after I experiment what's going on in the background and obviously saw it's matching with tiny knowledge I acquired from books. Just wanted to check if what I've understood is correct.
I have a fundamental program -- has 2 functions, first one is foo and the other is main (the entry point).
void foo(){
// do something here or dont
}
int main(){
int i = 0;
printf("%p %p %p\n",foo, &i, main);
system("PAUSE");
return EXIT_SUCCESS;
};
The output of the program is shown below, main's local variable i is located totally in a unrelated position. integer is a value type but checked it again with a char * pointer local to main and obtain similar results.
00401390 0022FF44 00401396
Press any key to continue . . .
I mainly understand that code and variables are allocated into different segments of memory (code segment/data segment). So basically is it right to say call stack collapses basic information about the execution of functions (their local variables, parameters, returning points) and keep them in the data segment?