CPP - Linked List Floyd's Cycle

In this video, ''and" operator is used in line no. 266. Why aren’t we using “or” operator?

Hello @tanyaa.sood,

Let’s understand the usage of these operator in a conditional statement like line 266.
or: using or will terminate the loop if both the conditions will hold false i.e. if and only if both the conditions fails.
and: while, using and will terminate the loop if any of the condition holds false.

Why we have used and at line 266?
suppose, we use or instead of and.

Case : second condition is false(i.e. fast->next is NULL) while first is true(i.e. fast!=NULL).
i.e. fast is not null but it points to null.
So, loop will execute and you will try to access fast->next->next.
But, fast->next is NULL and access NULL->next will give segmentation fault.

Thus, we use and to avoid this invalid access.

Hope, this would help.
Give a like if you are satisfied.

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.