Lesson 4.1.1.15

4.1.1.15 Stack frames in subroutine calls Quiz: AQA Computer Science, Unit 1

20 questions

In partnership with Revision Ninja

Lesson 4.1.1.15, Stack frames in subroutine calls: 20 multiple choice questions for the AQA Computer Science (7517), Unit 1: Fundamentals of programming, written with Revision Ninja.

Host it live on the board and students join with a game code on their own devices, or revise alone with Free Play. The answers are revealed in the game.

Host this setFree Play

The 20 questions

  1. What is a stack frame in the context of subroutine calls?

    • A type of loop that runs without a condition, repeating until the program is stopped by the user
    • A constant that stores the result of a function, so the value is fixed after the first call
    • A file that stores the whole program on disk, saved so that the program can be loaded again
    • A block of memory that holds the data for one subroutine call
  2. Which items are typically stored in a stack frame?

    • Only the program's source code, which is loaded onto the stack when the program starts running
    • Only global constants, which are kept in the frame so every subroutine can read them directly
    • Only the names of the subroutines, which the stack uses to find each one when it is called
    • Return address, parameters and local variables
  3. Why does a stack frame need to store the return address?

    • So the program can skip the caller, moving straight on to the next subroutine in the sequence
    • So the parameters can be deleted, freeing the memory they used before the subroutine returns
    • So the program knows where to resume in the caller after the subroutine finishes
    • So the subroutine can change its own name, which the program uses to keep track of each call
  4. When a subroutine is called, in what order are its frames typically added to the stack?

    • Frames are stored in a random order
    • All frames are merged into one
    • New frames are added to the bottom of a queue
    • New frames are pushed on top of the existing ones
  5. When a subroutine returns, what happens to its stack frame?

    • It is popped from the stack and its local data is discarded
    • It is sent to the printer, which records the local values of the subroutine as a log of the call
    • It remains on the stack for ever, so the program can look up old values from earlier calls
    • It is copied to the global variables, so that its local values can be used by other subroutines
  6. A main program calls A, and A calls B. How many frames are on the stack while B is executing, including the main program's frame?

    • 1
    • 4
    • 2
    • 3
  7. A recursive subroutine is called once from the main program. It then calls itself 4 more times before reaching its base case, with no other calls. How many stack frames exist at the deepest point, counting the main program?

    • 5
    • 7
    • 6
    • 4
  8. A subroutine is called with two parameters. Where are the parameter values held during the call?

    • In the return address alone
    • In the global data area only
    • In the stack frame for that call
    • In a file on disk
  9. Why is the stack an appropriate structure for subroutine calls?

    • Calls can only be made in alphabetical order
    • Subroutines never return to their callers
    • The stack holds every program's source code
    • Calls and returns happen in last-in, first-out order
  10. A subroutine returns a value. Where is the returned value typically passed back?

    • Into the return address
    • Into the subroutine's own local variables only
    • Into a new stack frame that is never freed
    • To the caller, after the frame is removed
  11. Which description best explains what the stack frame of a subroutine holds at the point of call?

    • The return address and the values needed for that call, such as its parameters and local variables
    • Only the subroutine's name, which is the one item the stack needs to find the code to run
    • The entire program's global variables, copied in full for each subroutine call that is made
    • The contents of the screen, saved so that the output can be restored after the subroutine ends
  12. A program's main part calls subroutine P, which calls subroutine Q, which then returns. Which frame is removed first?

    • The main program frame
    • The frame for P
    • The frame for Q
    • The frame for the first call of P
  13. Why do recursive calls need a stack?

    • Recursion only works with global variables, so the stack is used only for non-recursive calls
    • Each recursive call needs its own parameters and return address, which must be kept until it finishes
    • Recursive calls use no memory, because each call reuses the same values held in the processor
    • Recursion cannot be stored at all, so every recursive call must be run in a separate program
  14. What can happen if a recursive subroutine has no base case?

    • The subroutine stops after the first call, because the language detects the missing base case
    • The program runs in constant time, since each recursive call returns straight away without work
    • Frames keep being added until the stack runs out of memory
    • The stack is emptied automatically, so the program removes all frames when recursion starts
  15. A subroutine has three local variables and two parameters. How many values does its stack frame hold for those items alone?

    • 3
    • 6
    • 2
    • 5
  16. Which statement about stack frames is most accurate?

    • A stack frame exists only while its subroutine is executing
    • A stack frame stores only global constants
    • A stack frame is needed only for functions, not procedures
    • A stack frame remains after the subroutine has returned and program ends
  17. Why are local variables held in stack frames rather than in a single fixed memory area?

    • Each call needs its own copy, which the stack provides for each active call
    • Local variables must be stored on a printer, which keeps a copy of each value for the next call
    • Stack frames make global variables slower, so local variables are kept in a separate area
    • Local variables are not used at all when a subroutine is called, so no frame is needed for them
  18. When a subroutine ends and the program continues, which information from the frame is used to resume?

    • The local variable names
    • The return address
    • The subroutine's source code
    • The parameter names
  19. A stack has frames for main, A and B. B returns. How many frames remain on the stack?

    • 3
    • 1
    • 0
    • 2
  20. A program with a deep chain of nested calls causes a stack overflow. What is the most likely cause?

    • Too many frames were added without being removed, usually through unbounded recursion
    • The return addresses were stored in a file, so each return had to read the disk before continuing
    • The program used too many constants, which fill the stack with values that cannot be removed
    • The program used too few global variables, so the stack had no spare space for the calls to use

All AQA Computer Science quizzes