ProgrammingVery hard

A recursive function is called with depth 10^6 in C on a typical 8 MB stack with 64-byte frames. Is this safe?

  1. A. Yes, because recursion is always safe in C
  2. B. Yes, because 64 bytes is smaller than 8 MB
  3. C. Not reliably, since 10^6 frames of 64 bytes need about 64 MB, which exceeds the stack
  4. D. No, because recursion is forbidden by the C standard

Correct answer: C. Not reliably, since 10^6 frames of 64 bytes need about 64 MB, which exceeds the stack

10^6 frames of 64 bytes is 64 MB, which is far above the usual 8 MB stack. An explicit loop or stack in the heap is needed.

More C Programming questions

Exams that ask this topic