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.