Please solve doubt in Flatten a Tree

https://ide.codingblocks.com/s/23093
In the above code if I write the below code to print the linked list, I am getting a segmentation fault. Why??
while(l.head!=NULL){
cout<< l.head->data <<" --> ";
l.head = l.head->right;
}

hello @sahilkhan2312000131

no its working fine.

pls run this code and check ->

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.