ProgrammingHard
A recursive function prints a list after its recursive call returns, as in print(n) { if (!n) return; print(n->next); putchar(n->v + '0'); }. For the list 1 -> 2 -> 3, what is printed?
- A. 123
- B. 13
- C. 321
- D. 312
Correct answer: C. 321
The recursion goes to the end before printing, so each node prints on the way back up, giving the reverse order.
More C Programming questions
- In a 6-node list with values 10, 20, 30, 40, 50, 60, the standard slow and fast pointer method (slow moves one step, fast two steps, while…
- Which operation removes the k-th node (1-based) from a singly linked list in one pass with a pointer to the previous node, and handles…
- Which realloc pattern does not leak memory or lose the original block if the reallocation fails?
- A dynamic array doubles its capacity whenever it is full. Pushing N = 10^6 values costs about how many element copies in total?
- A function returns a pointer to a node created with malloc inside it. Which description is correct?
- Which statement about calloc(n, size) is guaranteed by the C standard?