I am trying to modify the value of local variable through another called function, but I am not able to figure out what all values pushed onto the stack are.
#include <stdio.h>
#include <string.h>
void fun()
{
int i;
int *p=&i;
int j;
for(j=0;*(p+j)!=10;j++);
printf("%d",j);
/* Stack Frame size is j int pointers. */
*(p+j)=20;
}
main()
{
int i=10;
fun();
printf("\n %d \n",i);
}
How exactly does j
in fun()
equal to 12
? I am trying to understand what values are pushed onto stack. More specifically, can we change the value of i
which is in main()
without using a for
loop in fun()
and is it possible to predict the value of j
inside fun()
?