reference binding to misaligned address 0x000009691a75 for type 'const int', which requires 4 byte alignment


  • 0
    C

    How do I fix the error mentioned in the code. When I run it on normal C++ compiler on linux, the code works but not here. What is the mistake?

    /**
     * Definition for singly-linked list.
     * struct ListNode {
     *     int val;
     *     ListNode *next;
     *     ListNode(int x) : val(x), next(NULL) {}
     * };
     */
    class Solution {
    public:
        ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
            int carry=0;
            ListNode* res;
            ListNode* temp=NULL;
            while (l1!=NULL || l2!=NULL || carry!=0){
                int s1=carry;
                if (l1!=NULL) {s1+=l1->val;}
                if (l2!=NULL) {s1+=l2->val;}
                if (res==NULL){
                    res=new ListNode(s1%10);
                    temp=res;
                }
                else{   
                    ListNode* l3=new ListNode(s1%10);
                    if (temp!=NULL)
                        temp->next=l3;
                    temp=l3;
                }
                carry=s1/10;
                if (l1!=NULL)
                    l1=l1->next;
                if (l2!=NULL)
                    l2=l2->next;
            }
            return res;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.