CS138 Lecture Notes - Lecture 12: Dynamic Array, Runtime System, Linked List
Document Summary
Use a vector instead except fir assignment #2. Vectors (and other library containers) are implemented using dynamic arrays. We are just looking under the hood to better understand what is going on. Array extent (size) must be a compile-time constant (usually) Array extent can be any positive integer: checked at instantiation of array. Can"t programmatically access extent of dynamic array except by cheating : instead, use instance of class vector or array. Can"t return an array from a function, but can return a ptr, so we do that. The run-time system needs to store the extent somewhere to know how many elements it is pointing to sot it can delete the right number of elements. Cant store extent with the pointer as it"s just an int* or string* so this would break normal pointer meaning. Can"t store the size right at the beginning of the array: eg: a[0] would break normal array indexing arithmetic.