I have been trying to create a pointer variable in the called function and somehow pass the value pointed by it to the main function. I wrote a few sample programs but it i still seem to be missing something out. and the challenge was to achieve this using pointers to pointers to pointers. Here is the code that I wrote and tested. I think am missing something obvious, can you guys point it. Thanks.
int one(int ***ptr)
{
static int *p,**pp,b=10;
p=&b;
pp=&p;
ptr=&pp;
printf("b:%d\tp:%d\tpp:%d\n",b,*p,**pp);
printf("Sub Ptr:%d\n",***ptr);
printf("Address of ***ptr:%d\n",&ptr);
return 32;
}
int main(int argc, char *argv[])
{
static int ***ptr;
int a=200,*b,**c;
b=&a;
c=&b;
ptr=&c;
printf("Main Ptr:%d\n",&ptr);
a=one(ptr);
printf("Main Ptr:%d\n",&ptr);
printf("Main Ptr:%d\n",***ptr);
system("PAUSE");
return 0;
}
I get an output of 32 which is the return value of the function. Is it possible to get the value of 10 which is pointed in the called function.
I also tried global declaration but din work either. I would like to maintain the local declaration and see if its possible...