ダングリングポインタが値を格納できないのはなぜですか?なぜ0をスローするのですか? 解放された同じメモリを指しているため。何らかの値を保存しようとすると、なぜ 0 になるのでしょうか?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p;
p=(int*)malloc(sizeof(int)*5);//allocating memory in heap
printf("%p\n",p);
free(p); //freeing memory
printf("%p\n",p); //still pointer same loaction(dangling pointer)
scanf("%d",p); // why cant i scan if it is still pointing same location
// i know memory is delete but why 0 is thrown?
printf("%d\n",*p);// i am getting zero here?
}