330 views
0 votes
0 votes

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 ?

Please log in or register to answer this question.

Related questions

4 votes
4 votes
2 answers
2
sh!va asked Jul 16, 2016
1,277 views
In C/C++ an array of pointers is same as(A) Pointer to array(B) Pointer to pointer(C) Pointer to function (D) Pointer to structure
1 votes
1 votes
1 answer
4
shikharV asked Nov 15, 2015
1,256 views
In circular linked list, insertion of a node at the end involves pointer modification:(A) one(B) two(C) three(D) none