LET'S TALK TECHNICAL

This blog is intended to help people prepare for the job interviews and improve their analytical skills. We have posted difficult datastructures and algorithm questions and puzzles. Interview experiences section is for the people to post their interview experiences.Views expressed here are of their personal and the blog author doesn't take any responsibility for the same.

-

Followers

Jobs

Saturday, November 10, 2007

How to check if the stack grows up or down?

Instantiate a local variable in main function(caller) and instantiate another local variable in callee function. Compare both the addresses. If address of local variable declared in main in less than the address of local variable in function(callee) then the stack is growing towards higher address.
Here is the Program which does this:
int main()
{
int localinmain;
CheckStackGrowth(&localinmain);

}

void CheckStackGrowth(int *localinmain)
{
int localinfunction;
if(localinmain < &localinfunction)
printf("Stack is growing downwards.\n");
else
printf("Stack is growing upwards.\n");


}

No comments:

Post a Comment

Popular Posts