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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:16:41+00:00 2026-06-07T21:16:41+00:00

I was reading about a few basic operations on linked list and I saw

  • 0

I was reading about a few basic operations on linked list and I saw two types of loops being used predominantly


struct node {
   int data;
   struct node *next;
}*start=NULL,*tmp;

The first loop was of the form

for(tmp=start;tmp->next!=NULL;tmp=tmp->next);

Using the above loop, now the tmp pointer points towards the last node in the list

The second loop was of the form

tmp=start;
while(tmp!=NULL)
{
     // do something
}

I think that both of them do the same work, but I’m not sure. Is there any difference?

  • 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-07T21:16:42+00:00Added an answer on June 7, 2026 at 9:16 pm

    I suppose your while loop is something like this.

    temp=start;
    while(temp!=NULL)
    {
         // do something
         temp= temp->next;
    }
    

    In your code of for loop, When you are out of the for loop, temp is not pointing to NULL. temp is pointing to end of the linked list. But in case of while loop, your temp is pointing to NULL after you exit the while loop and you don’t have tail(Unless you assign temp to any other temporary variable to change the logic of program) with you if you want to use it in the further steps. That is the only difference. Except that there isn’t much difference.

    You could have checked it by writing a small program and printing the results. I recommend you do it.

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

Sidebar

Related Questions

Mostly i have used $_SESSION , But while reading about Session i got few
I was reading about sorting of presorted list in which few numbers are unsorted,
I have a few questions about this after reading the iPhone documentation on it:
so I've been searching for the past few hours, reading on everything about how
Reading about Kohana templates and saw something I've never seen before: $this->template->title = __('Welcome
Reading about Django, I saw this: http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#ref-contrib-admin - the fancy simple to use admin
I started reading about implementing various data structures a few days back, and got
After doing some reading about the Module Pattern, I've seen a few ways of
I started learning Iphone development. As i'm reading about the cocoa development framework, few
I'm reading about visual programming languages these days. So I've thought up two paradigms.

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.