-1

This comment represent a given for a structure object.

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */

I can see the member variables are int val.

What is ListNode() : val(0), next(nullptr) {}. Is this an initialisation list? So after the contrsuctor call with ListNode() the program is then assigning val to 0 with val(0) and initializing the *next pointer with nullptr`?

henhen
  • 910
  • 2
  • 16
  • 34

1 Answers1

0

Those are three constructor functions for the struct. They initialize the two values stored in the struct.

See: https://stackoverflow.com/a/1127410/10559067

Grant
  • 77
  • 1
  • 7