Call Frames and Locals
Which memory region stores function call information and local variables when a function like add(a, b) is invoked?
- Stack
- Heap
- Global data area
- Disk buffer
- Stak
Dynamic Size at Runtime
When you read a number n from the user and then allocate an array of n integers at runtime, where is that memory typically taken from?
- Heap
- Stack
- CPU registers
- Const segment
- Heep
Local Variable Lifetime
What typically happens to a local variable defined inside a function after the function returns, such as int x = 5 inside foo?
- Its storage is automatically reclaimed when the stack frame is removed.
- It persists for the entire program even after the function returns.
- It moves to the heap automatically when the function ends.
- It becomes a global constant after the first assignment.
- It is saved to disk and reloaded on the next call.
Allocation Speed
For short-lived data such as a small temporary struct inside a function, which kind of allocation is generally faster?
- Stack allocation (push/pop)
- Heap allocation via allocator
- Disk paging
- Network buffer allocation
- Stak allocaton
Thread-Local Storage
In a multithreaded program where two threads each call a function with a local variable counter, where are those counters stored?
- On each thread's own stack
- In a single shared heap only
- In the CPU cache exclusively
- In the global constant area
- On the main thread's stack only
Fragmentation Risk
Which memory area is more prone to external fragmentation after many allocations and frees over time in a long-running program?
- Heap
- Stack
- Register file
- ROM
- Heeap
Returning Addresses
Why is returning the address of a local variable (for example, return u0026temp) considered a bug in many languages?
- Because the pointer refers to stack memory that is reclaimed after return
- Because pointers cannot be returned from functions at all
- Because heap memory is always faster than stack memory
- Because it always leaks memory by design
- Because local variables are stored in ROM and cannot be addressed
Big Objects
Which memory area is typically larger and suitable for storing big objects like a 10,000-element array created at runtime?
- Heap
- Stack
- CPU registers
- Instruction cache
- Static call stack
Recursion Limits
What is a common risk of extremely deep or infinite recursion, such as a function calling itself without a proper base case?
- Stack overflow due to running out of stack space
- Heap defragmentation
- Disk fragmentation
- CPU overheating
- Heep underflow
Heap Lifetime
Which statement best describes the lifetime of heap-allocated memory obtained via a dynamic allocation call?
- It remains allocated until it is explicitly freed or reclaimed by a runtime, not automatically at function return.
- It is always freed when the creating function returns.
- It becomes read-only exactly one second after allocation.
- It is automatically saved to disk at program exit and reloaded next run.
- It converts into stack memory after the first use.