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 9151177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:44:21+00:00 2026-06-17T11:44:21+00:00

This is my code to add node at beginning. void screate(ll *node) { ll

  • 0

This is my code to add node at beginning.

void screate(ll *node)
{
  ll *newNode=(ll *)malloc(sizeof(ll));
  printf("Enter number :\t");
  scanf("%d",&newNode->data);
  if(newNode->data != NULL)
  {
    newNode->next=node;
    node= newNode;
    screate(node);
  }
  else
  {
    free(newNode);
    newNode=NULL;
  }
}

Even i found same code here, I unable to figure out, why I getting wrong output.

This is the current node

56->78->77->NULL

But, when i’m trying to add new node at the beginning, then still I’m getting same output i.e. 56->78->77->NULL. Need Help !!

UPDATE

void show(ll *node){
while(node->next != NULL)
 {
  printf("%d->",node->data);
  node=node->next;
 }
printf("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-06-17T11:44:22+00:00Added an answer on June 17, 2026 at 11:44 am

    You’re assigning to node which is just a parameter to the function. Since it’s passed by value, this won’t update the version held by the calling function.

    You need to pass a pointer to it instead (i.e. ll **node) and change your code to assign to *node, and also changer the caller to add a & before the argument to take its address.

    void screate(ll **node)
    {
      ll *newNode=malloc(sizeof(ll));
      printf("Enter number :\t");
      scanf("%d",&newNode->data);
      if(newNode->data != NULL)
      {
        newNode->next=*node;
        *node= newNode;
        screate(node);
      }
      else
      {
        free(newNode);
      }
    }
    

    If you pass a pointer to something to a function, it can change the something but not the pointer itself. The natural conclusion is therefore to make the something itself the pointer – i.e. a pointer to a pointer.

    In principle you can take this pointer chaining as deep as you like, but in practice you won’t generally need anything more than “pointer to pointer to thing”.

    Couple of other points. Try to avoid variable names like l and ll as lowercase L’s can easily be confused with the digit 1 (and an uppercase I) in many fonts. Also, your use of a recursive call into screate() again would be potentially more efficient as a while loop instead. Some compilers will spot that it’s tail-recursive and optimise to a loop anyway, but I never like to rely on that sort of thing when it’s just as clear to use a loop in the first place.

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

Sidebar

Related Questions

I have this code: public void AddNode(string Node) { try { treeView.Nodes.Add(Node); treeView.Refresh(); }
Ok I have got this code: public void TraverseTree(TreeNode node) { TraverseTree(node.getLeftChild()); System.out.println(node.getKey()); TraverseTree(node.getRightChild());
I've write this code to add textview into table row, but I've problem for
I was wondering where in this code to add $stmt ->real_escape_string($password); in order to
I have my form in a table and I use this code to add
When I add this code to my Android 2.1 Java app, it fails: db=SQLiteDatabase.openOrCreateDatabase(Locations,
I want to add this code: <link rel=stylesheet type=text/css href=css/global.css /> <!--[if lt IE
I add this code in my activity public boolean onKeyDown(int keyCode, KeyEvent event) {
I have this quickBox2d code to add a cricle to the stage: var ball:QuickObject
I am using this code snippet to add KeyDown event handler to any element

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.