title: Runtime error in Linked List :member access within null pointer of type 'ListNode'
body: <p>I am given two non-empty linked lists representing two non-negative integers and i am trying to Add the two numbers and return the sum as a linked list.
  And i am getting an error which says</p>
  <p><strong>Char 18: runtime error: member access within null pointer of type 'ListNode' (solution.cpp)</strong>
  <strong>SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior</strong></p>
  <p>Why am i getting this array and How does i solve this?</p>
  <pre><code>class Solution {
  public:
      ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
          int carry=0,sum = 0;
          ListNode* res = new ListNode(0);
          while(l1-&gt;next !=NULL){
              sum = carry + l1-&gt;val + l2-&gt;val;
              if(sum&gt;9)
                  carry = 1;
              else
                  carry = 0;
              
              res = res-&gt;next;
              
              res-&gt;val = sum;
          }
          return res;
          
      }
  };
  </code></pre>
  <p>The error is showing in Line with code</p>
  <pre><code>         res-&gt;val = sum;
  </code></pre>