Prepare for the A Level Computer Science OCR Exam with engaging quizzes, detailed explanations, and effective study tips. Maximize your readiness and boost your confidence for exam day!

Practice this question and more.


Which programming concept is utilized to store temporary values during sub-routines?

  1. Queues

  2. Stacks

  3. Paging

  4. Arrays

The correct answer is: Stacks

The concept of storing temporary values during sub-routines is best captured by using stacks. A stack is a data structure that follows the Last In, First Out (LIFO) principle, meaning that the last value added to the stack is the first one to be removed. When a sub-routine is called, the current execution context, including local variables and return addresses, is pushed onto the stack. This allows the sub-routine to use these temporary values while it is running. Once the sub-routine completes its execution, the values can be popped off the stack, restoring the previous execution context and allowing the main program to continue from where it left off. This mechanism is fundamental in programming languages that support recursion, as it efficiently keeps track of multiple calls to sub-routines without losing the context of previous calls. The stack also helps manage memory in a structured way, making it easier to allocate and deallocate space for temporary data. While the other options—queues, paging, and arrays—are valid data structures, they do not operate on the same LIFO principle and are not specifically designed to manage temporary values related to sub-routine calls in the same way that stacks do.