CMPSC 16 Lecture Notes - Lecture 15: Dynamic Array, Segmentation Fault, Memory Leak

20 views2 pages
School
Course
Professor

Document Summary

Static variables: one copy that can be defined inside of a function (not recreated each time the function is called) Vector: dynamically sized array (can start w/ no elements) Syntax: vector v1; //int is the type that can be stored in it. V1. push_back(): adds an element to the end of the vector. V1 is on the stack, but it points to a dynamic array on the heap (stores the new length each time a new element is added) Shallow copy: when a copy of a vector points to the same item on the heap. Tip: when drawing the memory model with a pointer, just label the box p, not *p. D is a reference to a pointer to an int (start with d and go left from there) If int x, y" can assume x and y are 4 bytes apart (adjacent in memory)

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