Suppose, I have this program…
#include <stdio.h>
#include <stdlib.h>
int *g(void)
{
int *px;
px = (int*) malloc (sizeof(int));
*px = 10;
return px;
}
int main()
{
int y=*g(); /* Doubt */
printf("%d",y);
}
Now, if I modify the line labelled as ‘Doubt’ as :- int y=g(), then in the output, I get a garbage value. I am unable to understand why. Can anyone please explain ?