CMPT 125 Lecture Notes - Lecture 5: Stack (Abstract Data Type), C Dynamic Memory Allocation

15 views2 pages

Document Summary

Lecture 5 part 7 int foo (int n) { int ret = 3 bar(4); bar(8); return ret; int main() { foo(5) return 0; All local variables of a function are stored in the stack-frame. When the function completes, the variables become unavailable. Variables obtained from malloc() are stored in "global memory", and do not die when the function completes. Stack is a data structure with two principal operations: Push(element) adds an element to the collection. Pop() - removes the most recently added element from the collection. We add and remove only to/from the top. Each function call is added to the stack, when finished, we remove it from the stack and continue the with next function on top. Recursion is a powerful tool for solving certain kinds of problems. Recursion breaks a problem into smaller problems that are, in some sense, identical to the original, in such a way that solving the smaller.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents