A dangling pointer arises when an object is deleted or deallocated without modifying the value of the pointer, leading it to point to an invalid memory location. This can result in undefined behavior, including program crashes and security vulnerabilities, as the pointer may inadvertently access or modify unintended memory areas.