Difference in conditions

if i m writing

while( fast->link!=NULL && fast!=NULL )

{

    fast=fast->link->link;

    slow=slow->link;

}

i m not getting ans when number of nodes is even but getting when number of nodes is odd .

but if i write

while(fast!=NULL && fast->link!=NULL)
{

    fast=fast->link->link;

    slow=slow->link;

}

i m getting right answers for both.

Can u explain WHY?

The condition fast!=Null should be placed before fast->link!=Null because if fast is NULL then fast->link will cause error in the program.


Go through this discussion