Skip to main content
Logo image

Section 27.2 Pass Linked Lists to Functions

In the next video we’ll see how to use functions in conjunction with linked lists. In particular, we’ll enhance the previous example by moving the part that prints the linked list into a function.

If you cannot see this codecast, please click here.

Check Your Understanding Check Your Understanding

1.

    As in the previous question, you have created a linked list of three student records using the structure definition below:
    struct student {
         char    name[50];
         int     birthYear;
         float   gpa;     
         struct student *next;
    };
    
    Suppose also that the pointer start of type struct student * points to the first student in the list.
    How would you print the name and GPA of the second student in the list?
  • printf("%s has a gpa of %f.", start->next->name, start->next->gpa);
  • Correct
  • printf("%s has a gpa of %f.", start.next->name, start.next->gpa);
  • Not quite. Try again!
  • printf("%s has a gpa of %f.", start.next.name, start.next.gpa);
  • Not quite. Try again!
  • printf("%s has a gpa of %f.", start->next.name, start->next.gpa);
  • Not quite. Try again!