ProgrammingModerate

A linked list is reversed with the recursive function rev(n): if (!n || !n->next) return n; h = rev(n->next); n->next->next = n; n->next = NULL; return h. For the list 1 -> 2 -> 3, what is the new head value?

  1. A. 1
  2. B. 3
  3. C. 2
  4. D. 0

Correct answer: B. 3

The recursion reaches the last node first, and that node becomes the new head. The base case returns the original tail.

More C Programming questions

Exams that ask this topic