A program is a sequence of instructions stored in memory. The CPU fetches, decodes, and executes these instructions in a continuous cycle. Understanding this cycle explains performance, bugs, and security vulnerabilities.
| Region | Contents | Notes |
|---|---|---|
| Stack | Local variables, return addresses | Grows downward; fast; fixed size |
| Heap | Dynamically allocated objects | Managed by malloc/GC; flexible |
| Data | Global/static variables | Initialized at program load |
| Text (Code) | Compiled machine instructions | Read-only in most OSes |
Stack overflow occurs when recursive calls or large local variables exhaust stack space. Heap fragmentation can slow dynamic allocation.
Compiled languages (C, C++, Rust) translate source code to machine code ahead of time. Faster execution, but you must recompile for each architecture.
Interpreted languages (Python, JavaScript) execute source line-by-line at runtime via an interpreter. Slower but portable and interactive.
JIT-compiled (Java, C#, modern JavaScript engines) compile to bytecode, then to native code at runtime — combining portability with near-native speed.
In the fetch-decode-execute cycle, what does the Program Counter (PC) hold?
Which memory region stores local variables and function return addresses?
A compiled language differs from an interpreted one in that it
JIT compilation combines the benefits of
Stack overflow most commonly occurs due to