Sunday, March 14, 2010

Access the stack and change the local variable without Call by Reference.

void stack_main_access(void);
int main()
{
int loc_var=10;
clrscr();
stack_main_access();
printf("\nchanged value of loc_var %d \n",loc_var);
getch();
return 0;
}
void stack_main_access()
{
int num=0;
int *ptr=#

/*Searching the Exact Address of the Local Variable loc_var in Main() */
while(num!=5)
{
ptr++;
if(*ptr==10)
{
*ptr = 24;
printf("\nInside the IF %d \n",num);
num=5;
}
else
num++;
}
return;
}

The Program is compiled and checked using Turbo C compilers.

2 comments:

  1. this step is quite complex we can acheive it simpler using the directory steps

    ReplyDelete
  2. yes, true ...it can be done in simple steps ..however to be in safer side , I did it like this....thanks for your inputs...

    ReplyDelete