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?
- A. Yes, because recursion is always safe in C
- B. Yes, because 64 bytes is smaller than 8 MB
- C. Not reliably, since 10^6 frames of 64 bytes need about 64 MB, which exceeds the stack
- 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
- A bit set of 64 flags is packed in one unsigned long long. Which expression tests flag 17?
- What is the first printed value of this loop? for (int i = 3; i > 0; i--) printf("%d", i);
- int x = 0; while (x < 3) x = x + 1; printf("%d", x); What is printed?
- int count = 0; for (char c = 'a'; c <= 'z'; c++) if (c != 'e' && c != 'i' && c != 'o' && c != 'u') count++; printf("%d", count); What is…
- printf("%d", 3 > 2 ? 'Y' : 'N'); What is printed?
- char names[] = {"x", "yy", "zzz"}; printf("%zu", strlen(names[2])); What is printed?