1,634 views
0 votes
0 votes
operations :
(i) Pointer p1 is set to point at a new heap-dynamic variable.
(ii) Pointer p2 is assigned p1’s value.
(iii) The heap dynamic variable pointed to by p1 is explicitly de-allocated, but p2 is not changed by the operation.

This situation leads to which of the following :

(A) p1 becomes a dangling pointer
(B) p2 becomes a dangling pointer
(C) Both p1 and p2 are now dangling pointers
(D) Neither p1 nor p2 is now a dangling pointer

1 Answer

Best answer
3 votes
3 votes
Dangling pointers arise when an object is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the de-allocated memory.

Since P2 is pointing the memory location that has been de-allocated .So we can say P2 becomes dangling pointer.
selected by
Answer:

Related questions

0 votes
0 votes
1 answer
2
Gurdeep Saini asked Feb 1, 2019
639 views
is it dangling pointer ?int main(void) { int* p;printf("%d",*p); return 0;} https://ideone.com/IN77el
0 votes
0 votes
1 answer
3
iarnav asked May 5, 2017
701 views
#include <stdio.h int*fun() { intx=5; return&x; } int main(){ int*p=fun(); fflush(stdin); printf("%d",*p); return0; }Please explain this code, how's it's working line by ...