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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:26:52+00:00 2026-05-20T11:26:52+00:00

#include <iostream> using namespace std; int main() { struct list { string name; int

  • 0
#include <iostream>

using namespace std;
int main()
{
    struct list
    {
        string name;
        int age;
        double height;
        list *next;
    };
    list *first,*temp,*temp2;
    for (int i=0 ;i<4;i++)
    {
        list *newlist;
        newlist = new list;
        cout << " Enter the name : ";
        cin >> newlist->name;
        cout << " Enter the age : ";
        cin >> newlist->age;
        cout << " Enter the height : ";
        cin >> newlist->height;
        cout << " Name is: " << newlist->name << " " ;
        cout << " Age is: " << newlist->age << " ";
        cout << " Height is: " << newlist->height <<endl;
    }
    {
        list *newlist1;
        newlist1 = new list;
        newlist1->name = "Steve";
        newlist1->age = 23;
        newlist1->height = 2.3;
        newlist1->next=temp2;
        temp->next=newlist1;
        newlist1->next = temp2;
        temp->next = newlist1;
        temp2 = newlist1->next;
        temp2->next = newlist1->next;
        delete temp2;
        cout << " Name is: " << newlist1->name << " ";
        cout << " Age is: " << newlist1->age << " ";
        cout << " Height is: " << newlist1->height;
    }
}

Basically, what I’m doing is creating a linked list and inserting a new node in between node 2 and node 3 and deleting node number 3 out of 4 nodes (note for loop is 4 times).
And the next code after the loop is where I tried using code for insertion of a new node.

But after executing it says incompatible types in assignment of 'int' to char[20]' I don’t understand that.
Also, I wanted to know if my code is correct for the above intention.
I took temp2 to be the 3rd code by linking the newnode to the next node and temp to be the second node…

So can someone explain what the error meant so I can get it right? Thank you!

  • 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-05-20T11:26:52+00:00Added an answer on May 20, 2026 at 11:26 am

    I did your homework, spend some attention on the comments:

    #include <iostream>
    // you forgot to include string!
    #include <string>
    
    using namespace std;
    
    // type definitions usually go outside the main function!
    struct list
    {
      string name;
      int age;
      double height;
      list *next;
    };
    
    int main()
    {
    
      // mark the beginning with NULL!
      list *first = NULL,*temp,*temp2;
    
      for (int i=0 ;i<4;i++)
      {
        list *newlist;
        newlist = new list;
        cout << " Enter the name : ";
        cin >> newlist->name;
        cout << " Enter the age : ";
        cin >> newlist->age;
        cout << " Enter the height : ";
        cin >> newlist->height;
        cout << " Name is: " << newlist->name << " " ;
        cout << " Age is: " << newlist->age << " ";
        cout << " Height is: " << newlist->height <<endl;
    
        // is this the first node?
        if(first == NULL) {
          // yes, so set the first node
          first = newlist;
        } else {
          // no, set this node as the next node of the previous node!
          temp->next = newlist;
        }
        // set temp to the end of the list for next iteration
        temp = newlist;
    
      }
    
      // mark ending of list with NULL!
      temp->next = NULL;
    
      // creating extra node
      list *newlist1;
      newlist1 = new list;
      newlist1->name = "Steve";
      newlist1->age = 23;
      newlist1->height = 2.3;
    
      // insert between 2 and 3
      // temp2 holds node 3
      temp2 = first->next->next;
    
      // set the "next" pointer of element 2 to the new node
      first->next->next = newlist1;
    
      // append the rest of the old tail to the new node
      newlist1->next=temp2;
    
      // delete node 4
      // why 4? because 4 was the old 3 ! If we deleted the current node 3
      // we would delete the node that we just have inserted!
    
      //temp2 holds node 4
      temp2 = first->next->next->next;
      // link node 3 to 5
      first->next->next->next = temp2->next;
    
      // delete node 4
      delete temp2;
    
      // set to beginning of list
      temp = first;
    
      // separator
      cout<<"---------------"<<endl;
    
      // output the list to make sure it's correct!
      while(temp != NULL) {
    
        cout << " Name is: " << temp->name << " ";
        cout << " Age is: " << temp->age << " ";
        cout << " Height is: " << temp->height<<endl;
    
        temp = temp->next;
      }
    
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is code in which I am trying to implement a queue using linked
I got some problem with the linked list I've written. I dunno if it's
Possible Duplicate: Copy a linked list Hello stackoverflow! I am trying to learn more
I thought I understood how C/C++ handled struct member alignment. But I'm getting strange
I'm trying to figure out how exactly to use stat() to capture information about
I have developed one server pgm for multicasting in C++, when i register the
Suppose we have the following problem - we want to read a set of
The following program shows that we can use return or pthread_exit to return a
I'm trying to use a socketpair to have a parent process provide input to
I have been playing around with Template functions, and made a little logger program.

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.