ProgrammingModerate

A cyclic list has a head node whose next points back to itself. What does a naive while (p) loop starting from head do?

  1. A. It visits each node once and stops at head
  2. B. It stops after one iteration
  3. C. It crashes at compile time
  4. D. It never ends, because p never becomes NULL

Correct answer: D. It never ends, because p never becomes NULL

A cycle means p is never NULL, so the loop runs forever. Floyd's method or a visited check is needed to detect it.

More C Programming questions

Exams that ask this topic