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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:15:33+00:00 2026-06-13T05:15:33+00:00

To check a sample list imlpementation I tried the following code. But whenever i

  • 0

To check a sample list imlpementation I tried the following code. But whenever i am trying to display the result it is getting inside a loop. I cant find where is it getting wrong.

#include<stdio.h>
#include<stdlib.h>

typedef struct linkedlist
{
    int data;
    struct linkedlist *next;
}node;

int main()
{
    int ch,num;

    node *head=NULL;
    head=(node *)malloc(sizeof(node));
    node *new=NULL;
    new=(node *)malloc(sizeof(node));
    node *temp=NULL;
    temp=(node *)malloc(sizeof(node));
    printf("\n1.Insert to list");
    printf("\n3.Display the list");
    printf("\n Enter Choice->");
    scanf("%d",&ch);
    switch(ch)
    {
     case 1:printf("\n Enter data->");
            scanf("%d",&num);
            new->data=num;
            new->next=NULL;
            head->next=new;
            break;

     case 3: temp=head;
            while(temp!=NULL)
            {
                printf("\n %d",temp->data);
                temp=temp->next;
            }


                break;
     default:printf("Wrong Choice");
              break;

    }
    return 0;
 }
  • 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-13T05:15:34+00:00Added an answer on June 13, 2026 at 5:15 am

    There are two mistakes here.

    1. You are only allocating “new” once. This means you are reusing the same node every time the user enters “1” and actually linking it to itself.
    2. You shouldn’t be allocating a node for “temp” at all, since you are not using it. You are actually loosing the pointer to that allocated node with this line: case 3: temp=head; This is called a “memory leak.”

    I suggest that you study pointers a bit more; they seem to be confusing you.

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

Sidebar

Related Questions

I found this sample but its for web. Can any one check this proj.
i am trying to fetch data from SQLite to list view but my list
I have following requirements: Get questions from db in servlet. Display themin jsp. Check
Let me explain using this code sample: var commands1 = new List<int> { 1
i'm populating a list view to view my record, i've the following code... super.onCreate(savedInstanceState);
I have a simple list view with some check boxes in an alert dialog.
Possible Duplicate: White space at bottom of anchor tag Check out this sample page
This is a sample pgm to check the functionality of Sleep() function.This is a
I'm trying to build a simple environment check script for my firm's test environment.
I'm trying to write a simple stock check program, and I have a Table

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.