CS138 Lecture Notes - Lecture 5: Bounds Checking

48 views3 pages

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.

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