Chapter 3: Recursion Flashcards

1
Q

What information can you give me, just based on this call stack?

A
  • The greet function is called first, with name = maggie.
  • Then the greet function calls the greet2 function, with

name = maggie.

• At this point, the greet function is in an incomplete,

suspended state.

  • The current function call is the greet2 function.
  • After this function call completes, the greet function will

resume.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Suppose you accidentally write a recursive function that runs

forever. As you saw, your computer allocates memory on the

stack for each function call. What happens to the stack when

your recursive function runs forever?

A

The stack grows forever. Each program has a limited

amount of space on the call stack. When your program runs

out of space (which it eventually will), it will exit with a stackoverflow

error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly