ProgrammingHardGATE CS · Campus placements
Is the C standard guaranteed to remove stack frames of tail-recursive calls, so that deep tail recursion cannot overflow the stack?
- A. No, the standard does not require tail-call elimination, so deep recursion may overflow the stack
- B. Yes, every conforming compiler must optimise tail calls
- C. Yes, but only when compiled with optimisation enabled
- D. No, C forbids recursion inside functions with a return value
Correct answer: A. No, the standard does not require tail-call elimination, so deep recursion may overflow the stack
Tail-call elimination is an optimisation, and the C standard leaves call-stack use to the implementation. Competitive solutions should write deep recursions as loops with an explicit stack.
More C Programming questions
- int a[6] = {1, 2, 3, 4, 5, 6}; int p = a, q = a + 5; while (p < q) { int t = p; p++ = q; q-- = t; } What is a[1] afterwards?
- uint8t x = 0xB4; What is the lowest set bit of x, computed as x & (uint8t)-x?
- uint8t rev(uint8t x) { uint8t r = 0; for (int i = 0; i < 8; i++) { r = (uint8t)((r << 1) | (x & 1)); x >>= 1; } return r; } What is…
- int a[] = {4, 9, 16}; int p = a; What is (p + 2)[-1]?
- To compute a b mod m with 0 <= a, b < m <= 1000000007 in a competitive program, which expression is correct?
- Which expression tests whether bit k of an unsigned x is set?