I am doing the leetcode question https://leetcode.com/problems/add-two-numbers/
Definition of a ListNode is:
// Definition for singly-linked list.
struct ListNode {
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
};
When I check if a list is hit the end, I used:
int v1 = h1 == NULL? h1->val:0; // h1 is defined before: ListNode* h1 = l1;
But it returns a runtime error, but if I changed it to
int v1 = h1? h1->val:0;
it is accepted.
Why is that?