Why we mention string assigning character pointer as a dangling pointer in below code ?
void func()
{
char *ptr;
*ptr = "dog";
char *p1 = malloc(sizeof(char));
char *p2;
*p1 = 'a';
*p2 = 'b';
}
Here p2
is called 'Dangling pointer' but *ptr
is not calling dangling pointer. Why is it so ?
Aucun commentaire:
Enregistrer un commentaire