Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7564365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:53:09+00:00 2026-05-30T13:53:09+00:00

This is a question posed to me in an interview. A single linked list

  • 0

This is a question posed to me in an interview.

“A single linked list is there in the memory. You have to delete a node. You need to write a function to delete that node, which takes only the address of the node to be deleted as input and nothing else(including head)”

I gave the answer similar to the one answered in the below post — Copying the contents of the next node into the node to be deleted and deleting the next one.

Deleting a middle node from a single linked list when pointer to the previous node is not available

But the interviewer asked me again, what if I pass the address of the last node. I told him, since the next will be a NULL, copy that NULL into the data field along with the address to the next node which is also NULL. Then he told me there will be a problem of dangling pointers… which I didn’t understand a bit. Can some one please throw light into this problem ? Is there a generic solution to this ?

Update (Two days later) : A little bit additional. Considering there is no special node at the end of the list. And the last node points to NULL and if that node is given as input, how to make the before last node point to NULL. Or is it impossible ?

Simply put : If a node is given as input to a function, how to make the pointer that references it, point to NULL

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:53:10+00:00Added an answer on May 30, 2026 at 1:53 pm

    Dangling Pointer:

    (http://en.wikipedia.org/wiki/Dangling_reference)

    Dangling pointers and wild pointers in computer programming are
    pointers that do not point to a valid object of the appropriate type.
    These are special cases of memory safety violations.

    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 deallocated memory. As the system
    may reallocate the previously freed memory to another process, if the
    original program then dereferences the (now) dangling pointer,
    unpredictable behavior may result, as the memory may now contain
    completely different data.

    In your answer, to delete the given node you actually delete the next node, which might be being referenced by a pointer. That’s how dangling pointer problem arise.

    (1) There are no outside references to the list, as you clarify in a note.
    (2) Dangling pointer problem can arise, as the interviewer said.

    Both (1) and (2) cannot be correct at the same time. Which means there is a misunderstanding somewhere.

    About Deleting the Last Node:

    But the interviewer asked me again, what if I pass the address of the
    last node. I told him, since the next will be a NULL, copy that NULL
    into the data field along with the address to the next node which is
    also NULL.

    I think you are confusing these two things: (1) A pointer p that points to NULL, (2) A linked list node that has NULL in its data field.

    Suppose the data structure is a -> b -> c -> d. Writing NULL to d’s data field will not magicly make c to have a NULL pointer in its next field.

    You can delete the last node if the linked list always has a special last node that will never be deleted. For example, a -> b -> c -> d -> LAST where LAST has a special value in its data field that denotes it is really the last element. Now to delete d, you could delete LAST and write the special value in d’s data field.

    Maybe these are exactly what you tried to tell during the interview, in which case there must have been some miscommunication between you and the interviewer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A co-worker posed this question to me, and I told them, No, you'll need
this was an interview question posed to me..I vaguely answered it uses Java reflections..but
I have seen this question posed regarding Silverlight 2 but I have not seen
I am trying to write a simple program for this interview question: Write a
I need help in understanding this interview question: Q: Find an algorithm to find
This is somewhat related to the question posed in this question but I'm trying
This was the main question posed by Greg Wilson's bits of evidence presentation. I'm
This question was posted on some site. I didnt find right answers there, so
I know this question has been posed several times, but my goal is slightly
This is a newbie question in R. If you have two libraries in R

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.