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 6 of 6.

MaheshBabu said:   1 decade ago
Anjali you are giving nice explenation thanks for giving me such type of explenation.

Hemant singh said:   1 decade ago
We are assigning the address to p not the value where as the free() function clear the content of the memory location not the address.

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

The Guide said:   1 decade ago
free() deletes the memory that is pointed by p but not the address of p i.e in the above example the free() deletes a memory that p points to an integer.

Arnab Bhattacharya said:   1 decade ago
"134520952"

That's the answer I got using this online compiler...!!!
Please explain...!!!!

Prasenjeet Mahtha said:   1 decade ago
free() function clears the memory space. It does not remove the declared pointer.

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


Post your comments here:

Your comments will be displayed after verification.