Midpoint of linked list

my code is showing run time error,what is the problem
my code is:
node* kthnode(nodehead,int k)
{
node
slow=head;
node*fast=head;
for(int i=1;i<=k;i++)
fast=fast->next;

while(fast!=NULL)
{
    fast=fast->next;
    slow=slow->next;
}
return slow;

}

Hello @sawan_verma,

Always share your code using Online Coding Blocks IDE.
The way you have shared it is by introducing syntax errors to it.

And also share your entire code.
What if the run-error was due to some other logic in the code?

BTW the logic of your code is wrong as after executing the for loop, fast will always point to NULL.
So, while loop will never execute.

Correct it and share your entire code.

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.