Getting error member access within null pointer of type 'struct ListNode' on line 30

  class Solution {
public:
    ListNode* removeNthFromEnd(ListNode* head, int n) {
        
       ListNode* dummy = new ListNode(0);
        
    ListNode* ptr1=head;
         
        int count=0;
        
        while(ptr1!=NULL){
            
            count++;
            ptr1=ptr1->next;
            
        }
        
        count=count-n;
         ptr1=dummy;
        while(count>0){
            count--;
            ptr1=ptr1->next; //getting error in this line
        }
        
        ptr1->next=ptr1->next->next;
         return dummy->next;
    }
};

you assign prt1 to dummy with have size = 1 if your count > 1 then your ptr1 become null and you code try to extract next of null…

What the head value?