COP2253 Zybooks Chapter Five Flashcards
array
a special variable having one name, but storing a list of data items, with each item being directly accessible
element
used to refer to each item in an array
What statement declares a reference variable and allocates an array?
dataType[] arrayName = new dataType[numElements]
common for loop structure for iterating through an array
for (i = 0; i < myArray.length; ++i) { // Loop body accessing myArray[i] }
temporary variable
a variable used briefly to store a value (useful for swapping)
enhanced for loop (or for each loop)
for loop that iterates through each element in an array
loop variable
a variable whose scope is limited to the loop
perfect size array
an array where the number of elements is exactly equal to the memory allocated
oversize array
an array where the number of elements used is less than or equal to the memory allocated
oversize array declaration
int[] myArray = new int[1000];
int myArraySize = 0;
oversize arrays typically use three variables:
the array reference, the current size, and a constant for the array capacity
a method that expects a perfect size array as an argument will have:
one parameter for the array reference, but no parameter for the array size
a method that expects an oversize array will have:
two parameters to pass the array, one for the array reference and one for the array size
a method can return at most:
one item
side effect
an error that unintentionally modifies data