CMPSC 16 Lecture Notes - Lecture 15: Dynamic Array, Segmentation Fault, Memory Leak
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)