Chapter 8
in an array declared as array[n], the index goes from :
0 to n - 1
it is a compile error to leave out the index operators in an assignment statement, as shown below:
float costary[20]; ... costary = quantity * price;
it is most likely a logic error to leave out the index operators in a scanf statement, as shown in the following example. in this case costary is the address of the array and the input will be placed in the first element of the array. even when this is the desired result, you should code it with the index operators as shown:
float costary[20]; ... scanf("%f", costary); scanf("%f", &costary[0]);
when initializing an array when it is defined it is a compile error to provide more initializers than there are elements.
true
invalid indexes are often created by invalid coding in a for statement. for example, given an array of ten elements, the following for statement logic error results in an index value of ten being used. although it loops 10 times, the indexes are 1 through 10, not 0 through 9.
for(i = 1; i <= 10; i++)
three things are needed to declare and define an array
its name, type, and size.
a binary search is a much faster algorithm. in the binary search, each test removes half of the list from further analysis. the data must be ordered.
true
a frequency array is an array whose elements show the number of occurrences of data values in another array.
true
a one dimensional array is a fixed sequence of elements of the same type.
true
a two dimensional array is a representation of a table with rows and columns
true
an array must be declared and defined before being used. declaration and definition tell the compiler the name of the array, the type of each element and the size of the array.
true
an array reference is a postfix expression with the opening and closing brackets as operators.
true
another cause of invalid indexes is an uninitialized index. make sure your indexes are always properly initialized.
true
if a one dimensional array is completely initialized when it is declared, it is not necessary to specify the size, but it is recommended.
true
initialization of all elements of a fixed length array can be done at the time of the declaration and definition.
true
it is a compile error to omit the array size in the parameter declaration for any array dimension other than the first.
true
searching in the process of finding the location of a target among a list of objects.
true
the bubble sort divides the array into sorted and unsorted sublists. in each pass, the algorithm bubbles the smallest element from the unsorted list into the sorted sublist.
true
the elements of arrays are not initialized automatically. you must initialize them if you want then to start with known values.
true
the insertion sort divides the array into sorted and unsorted sublists. in each pass the algorithm inserts the first element from the unsorted list into the appropriate place in the sorted sublist.
true
the most common logic error associated with arrays is an invalid index. an invalid index used with an assignment operator either causes the program to fail immediately or destroys data or code in another part of the program and causes it to fail later.
true
the selection sort divides the array into sorted and unsorted sublists. in each pass, the algorithm chooses the smallest element from the unsorted sublist and swaps it with the element at the beginning of the unsorted sublist.
true
the sequential search starts at the beginning of the array and searches until it finds the data or hits the end of the list. the data may be ordered or unbothered.
true
to exchange the value of two elements in an array, you need a temporary variable.
true
to initialize all elements in an array to zero, all you need to do is initialize the first element to zero.
true
to pass a variable size array to a function, you need either to include the variable defining the array size to use an asterisk.
true
to pass a whole variable length array to a function, you need to also pass its size.
true
to pass the whole array to a function, you only use the name of the array as an actual parameter.
true
we can access the individual elements of an array using the array name and the index
true
we can also pass the whole array to a function. in this case, only the address of the array will be passed. when this happens, the function has access to all the elements in an array
true
we can fill the elements of an array by using a loop to read the values from the keyboard or file
true
we can pass an individual element of an array to a function either by value or by address.
true
when an array is partially initialized, the rest of the elements are set to zero.
true
you cannot copy all elements of one array into another with an assignment statement.
you need to use a loop