COP 3502 Chapter Notes - Chapter 7: Foreach Loop, Array Data Structure

40 views2 pages

Document Summary

A single dimensional array can reference a large collection of data. An array stores a fixed sized sequential collection of elements of the same type. Once an array is created, its size is fixed. An array reference variable is used to access the elements in an array using an index. (i. e. arrayrefvariable [0], arrayrefvariable [1], arrayrefvariable [2]) Declaring array variables elementtype[] arrayrefvar; e. g. int[] array; All elements within the array will have that type. (e. g. double[] arrayrefvar contains elements of the double type) Declaration of an array variable does not allocate any space in memory for the array. Instead, it only creates a storage location for the reference to an array. After array variable is declared, the new operator can be used to assign references to the variable. arrayrefvar=new elementtype[arraysize]; e. g. array=new int[5]; Declaring and assigning a reference can be done in one line of code. elementtype[] arrayrefvar=new elementtype[arraysize]; e. g. int[] array=new int[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

Related Questions