CS138 Lecture Notes - Lecture 5: Bounds Checking
Document Summary
C-style arrays are almost the same in c and c++ Must state max size (extent) up front and must be compile-time constant: eg: const int or explicit positive integer, not variable int a[15]; const int n=15 int b[n]; int m cin>>m; int c[m]; In the standard library for c++ 11, there is a library class called array : adds a lot of confusion to dimensions. Using c-style arrays, references to individual elements are unchecked at run-tome: possibly unsafe, can write a[i]=a+i. Often have to pass in extent of an array as extra parameter to functions int findmax (vector a) { int max=0; for (int i=0;imax) { max=a[i]; C++ (and java and other languages) have library element called vector : safe, generic, dynamically resizeable array, more flexible/safer but possible less efficient, under the hood, vectors are implemented as arrays plus same magic.