Answer the following questions true (T) or false (F)

1. The programmer should always use a defined constant in an array declaration.

2. When using an array, it is perfectly legal to access indexed variables with index values less than 0 or greater than or equal to the declared size of the array.

1. True
Explanation: The reason is flexibility. A program with an array with declared size of 5 only works with a maximum of 5 of whatever the array holds. If things change so that we need to process 17 of these things, we are faced with the difficult and error prone task of finding all places in the program that 5 is used as an array size, including situations where someone has done arithmetic with the 5 and some other number. Better to use a defined constant from the start.
2. False
Explanation: These index values are out of range, or simply illegal. The compiler cannot catch this. Unless you access protected memory doing this, the C++ runtime system will not catch this mistake either. The programmer has the obligation of detecting illegal index values or assuring there will be none.

Computer Science & Information Technology

You might also like to view...

Which of the following declarations creates a two-dimensional array?

(A) Dim newVar(2, 2) As Double (B) Dim newVar As Integer (C) Dim newVar(2) As Double (D) Dim newVar(2)

Computer Science & Information Technology

You have chosen Full Screen View while working on your Word document, and your toolbar has disappeared. How do you get it back?

What will be an ideal response?

Computer Science & Information Technology