Computer Science 1037A/B Lecture 1: Arrays

22 views3 pages

Document Summary

Array size is (often) fixed at the time of declaration. Array is a data structure that represents a collection of the same types of data. C++ requires that the array size used to declare an array must be a constant expression. Right int size = 4; double mylist[size]; const int size = 4; double mylist[size]; The array elements are accessed through the index. After an array is created, an indexed variable can be used in the same way as a regular variable. Accessing array elements using subscripts beyond the boundary does not cause syntax errors, but the operating system might report a memory access violation. Declaring, creating, initializing in one step: datatype arrayname[arraysize] = {value0, value1,, valuek}; Example: double mylist[4] = {1. 9, 2. 9, 3. 4, 3. 5}; Using the shorthand notation, you have to declare, create, and initialize the array all in one statement. Wrong double mylist[4]; mylist = {1. 9, 2. 9, 3. 4, 3. 5};

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