Try noting down the address of a local variable. Call another function with a local variable declared in it and check the address of that local variable and compare!.
#include < stdio.h >
#include < stdlib.h >
void stack(int *local1);
int main()
{
int local1;
stack(&local1);
exit 0;
}
void stack(int *local1)
{
int local2;
printf("\nAddress of first local : [%u]", local1);
printf("\nAddress of second local : [%u]", &local2);
if(local1 > &local2)
{
printf("\nStack is growing downwards.\n");
printf " Stack is growing to Lower address" );
}
else
{
printf("\nStack is growing upwards.\n");
printf " Stack is growing to Higher address" );
}
printf("\n\n");
}
#include < stdio.h >
#include < stdlib.h >
void stack(int *local1);
int main()
{
int local1;
stack(&local1);
exit 0;
}
void stack(int *local1)
{
int local2;
printf("\nAddress of first local : [%u]", local1);
printf("\nAddress of second local : [%u]", &local2);
if(local1 > &local2)
{
printf("\nStack is growing downwards.\n");
printf " Stack is growing to Lower address" );
}
else
{
printf("\nStack is growing upwards.\n");
printf " Stack is growing to Higher address" );
}
printf("\n\n");
}
This is really helpful! Thanks :)
ReplyDeletePlease post more
Am posting more at my new site http://beacrazyprogrammer.com/
ReplyDeletedo checkout