(e-mail address removed) wrote:
the above appraoch is right .... but my question was different....
let me re-format it to fit ....
# include <stdio.h>
void change(int *);
int main()
{
int i=5;
change(&i);
i=6;
/* next line prints 6 as we all know, how to make it print 6 without
changing main() function is the question */
printf("%d",i); //it should print 23 instead of 6
}
void change( int *i)
{
*i=23;
//write some code here so that output of printf in main will be 23 not
6
}
1) I can think of no possible valid reason to want to do this
2) Standard C provides absolutely NO mechanism to allow this
3) Any mechanism that you find that "works" when you try it might do
something *completely* different if you change anything at all, compiler
switches, compiler version, change a compiletely unrelated line of code
etc. That is completely ignoring the fact that a different compiler or
different architecture may well be completely different.
You can't relyably do it by changing the return address because the
function might be inlined by the compiler and therefor there not *be* a
return address.
You can't do it by changing the executable code because the compiler
might change the code generated so that fails for any reason at all.