Code running right in devcpp but not on ide

#include
using namespace std;

class node{
public:
int data;
node* next;

node(int d){
    data=d;
    next=NULL;
}

};

void addattail(node* &head,int data){
if(head==NULL){
head=new node(data);
return;
}
node* temp=head;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=new node(data);
return;
}

void formlist(node* &head,int n){
int data;
while(n!=0){
cin>>data;
addattail(head,data);
n–;
}
return;
}

void print(node* head){
node* temp=head;
while(temp!=NULL){
cout<data<<" ";
temp=temp->next;
}
cout<<endl;
}

void appendktofront(node* &head,int k){
node* slow=head;
node* fast=head;
while(k!=0){
fast=fast->next;
k–;
}
while(fast->next!=NULL){
fast=fast->next;
slow=slow->next;
}
fast->next=head;
node* temp=slow->next;
slow->next=NULL;
head=temp;
return;

}

int main() {
int n;
cin>>n;
node* head;
formlist(head,n);
int k;
cin>>k;
appendktofront(head,k);
print(head);
return 0;
}

hey @Aayush-Mahajan-2206170693038609, please this code saved in Coding Blocks ide because text gets mismatch here.

hey @Aayush-Mahajan-2206170693038609, in main function,you should initialise the head to NULL while declaring.

it runs but now giving runtime error in 2 testcases

hey @Aayush-Mahajan-2206170693038609, you k can be greater than N also.It is given in the question. In that case you should make k=k%N;
I have made changes to your code. You can check them here https://ide.codingblocks.com/s/108319

yes it worked thanks

hey @Aayush-Mahajan-2206170693038609 , if your query is resolved. Please mark this doubt as resolved and rate me on the basis of your experience.
rating option will appear when to mark this doubt as resolved

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.