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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:17:55+00:00 2026-06-09T22:17:55+00:00

I am trying to print the linked list using C.But it is printing me

  • 0

I am trying to print the linked list using C.But it is printing me empty when I execute my ./a.out. Can someone help me out where I am doing wrong.Thanks.

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

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

int main()
{
        node *start,*temp;
        start = (node *)malloc(sizeof(node));
        temp = start;
        temp -> next = NULL;
        while(1)
        {
                int query;
                printf("1.Insert\n");
                printf("2.Print\n");
                printf("Enter your choice:\n");
                scanf("%d",&query);
                if(query==1)
                {
                        int data;
                        printf("Enter the element to be inserted.\n");
                        scanf("%d",&data);
                        while(start->next!=NULL)
                        {
                                start = start -> next;
                        }
                        start->next = (node *)malloc(sizeof(node));
                        start = start->next;
                        start->data = data;
                        start->next = NULL;
                }
                else if(query ==2)
                {
                        printf("The list is as below:\n");
                        while(start->next!=NULL)
                        {
                                printf("%d \t",start->next->data);
                                start=start->next;

                        }
                }
                else
                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-09T22:17:57+00:00Added an answer on June 9, 2026 at 10:17 pm

    Whenever you insert an element, you move start pointer to the one before NULL. Thus, whenever you want to print the list, start->next is NULL, and nothing could be printed.

    You should use temp instead for both element insertion and list output. Just remember to point temp back to start before walking through the list.

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

Sidebar

Related Questions

I'm trying to reverse a linked list by using C++ and then print out
I am trying to print the reverse linked list. But I am getting only
I'm trying to print out a list of products on a page. This is
I am trying to print a particular text using awk if string is empty.
I'm trying to print the list of a singly linked list that I referred
I am trying to implement the linked list data structure using java, it works
I'm trying to create a linked list, I've got it working, but I'm still
I am trying to create a complete binary tree using a linked list, instead
I have a linkedList using nodes. I have it printing out alphabetically but now
I am trying simple linked list Collection program, but it is not giving me

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.