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

  • SEARCH
  • Home
  • 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 9191787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:46:13+00:00 2026-06-17T20:46:13+00:00

I was writing a function which removes a node in a linked list, whose

  • 0

I was writing a function which removes a node in a linked list, whose input is a pointer to a linked list. If the function removes a linked list that has only one node, the function will make the pointer point to NULL. Here’s part of the code:

void remove(dlinkNode_t *start){
    //some previous code
    if(start->next==NULL){//meaning we're removing the head of the linked list
        dlinkNode_t current=start;  //get a temp pointer to point at this node
        start=NULL;    //make start point to null
        free(current); //free the head
        return;
    }
    // More code

In main I created a linked list with one node, and passed this linked list to remove function to free it. Here’s the code:

int main(){
    dlinkNode_t *node1=create();  //creates a node and make node1 point at it
    remove(node1);  //now node1 should point at NULL
    if(node1==NULL)
        printf("hi");
    return 0;
}

But I didn’t see the hi printed. I don’t know why the if statement didn’t pass. Any ideas?

  • 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-06-17T20:46:14+00:00Added an answer on June 17, 2026 at 8:46 pm

    A new copy of the pointer is made in the local scope of remove. Any changes you make to the pointer will only be visible in that scope. Any changes that you make to the value being pointed to by a pointer will return to the calling scope.

    You can solve this problem in one of two ways :

    • Return the edited pointer

      node1 = remove(node1); 
      

      and make the change in remove as well.

      dlinkNode_t * remove(dlinkNode_t *start){
          //some previous code
          //Function code
          return start;
      
    • Or you can pass a pointer to the pointer start and then manipulate that pointer.

      Function call :

      remove(&node1);
      

      Function definition :

      void remove(dlinkNode_t **start){
          //some previous code
          if((*start)->next==NULL){ // meaning we're removing 
                                    // the head of the linked list
              dlinkNode_t current=**start; //get a temp pointer
                                           // to point at this node
              **start=NULL;  //make start point to null
              free(current); //free the head
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a Function that has a return-type which will dynamically change depending
I'm writing a function that requires an input vector of dates which I specify
I'm writing a function which will drop a table if it already exists. It
I'm writing a basic function in PHP which takes an input string, converts a
I'm currently writing a function what would create a zip file, which will be
I am writing a reset function within my app which will restore my sqlite
I am writing a program which contains a function that checks if a number
I am writing a function in which I need to read a string contains
I'm writing a function, which determine the number of useful bits of a 16
I'm writing a function intended to sanitize a poorly formatted string which the php

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.