In technical interviews, sometimes candidates are asked how they would find the address of the top of the stack in their system by programming in C. One simple program that should work mostly is:
int main()
{
int i;
printf("Top of the stack is %p", &i);
return 0;
}
As local variables are stored on stack, this would give an approximate top of stack. There can be variations of this program that are also few-liners like above and give more accurate results. Any more example piece of code to find stack top?
int main()
{
int i;
printf("Top of the stack is %p", &i);
return 0;
}
As local variables are stored on stack, this would give an approximate top of stack. There can be variations of this program that are also few-liners like above and give more accurate results. Any more example piece of code to find stack top?