In the above pgm, why *p is giving some junk value?Code:static int *p;
void main()
{
point_update(&p);
printf("%d",*p);
}
point_update(int **q)
{
int x = 5;
*q = &x;
}
Printable View
In the above pgm, why *p is giving some junk value?Code:static int *p;
void main()
{
point_update(&p);
printf("%d",*p);
}
point_update(int **q)
{
int x = 5;
*q = &x;
}
When control returns from the point_update function, the local variable x no longer exists, hence dereferencing p in main leads to undefined behaviour. Also, to print a pointer, you should be using the %p format specifier, not %d, and you should cast the pointer argument to void*. Oh, and void main should be int main, and you should declare point_update before using it.
In addition to all that laserlight has said, specify the return type of point_update() as well.
In addition to allthat grumpy and laserlight and std10093 said, you need to have a prototype declared before you call a function that takes a variable number of parameters. In this case, the prototype for the function printf() is in the standard header <stdio.h>
Code:#include <stdio.h>
/* ... */