C Programming - Memory Allocation - Discussion

Discussion Forum : Memory Allocation - Find Output of Program (Q.No. 1)
1.
What will be the output of the program?
#include<stdio.h>
#include<stdlib.h>

int main()
{
    int *p;
    p = (int *)malloc(20); /* Assume p has address of 1314 */
    free(p);
    printf("%u", p);
    return 0;
}
1314
Garbage value
1316
Random address
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
57 comments Page 5 of 6.

Apeksha said:   1 decade ago
This kind of pointer is known as "Dangling pointer".

Sowmiya said:   9 years ago
This is also called dangling pointer.

How it will print 1134?

Ankit said:   1 decade ago
As we free the address allocated how the meory is allcoated ?

Riyaz said:   1 decade ago
Yes anjali you are very correct. Thanks for your explanation.

AnubisYe said:   9 years ago
/* Assume p has address of 1314 */

Please explain this part.

Anshul said:   1 decade ago
This is not recommendable as it leads to dangling pointer.

Chandrabhan said:   1 decade ago
There is no any option in output list. O/P = 145711224.

Sundar said:   1 decade ago
@Mohit Dwivedi

What you said is exactly correct.

Prajesh Bhushan said:   2 decades ago
Please help me understand the logic behind !

Rinkoo said:   1 decade ago
Saradhi & boobal. I like your answer.


Post your comments here:

Your comments will be displayed after verification.