Find the error in each of the following program segments and correct the error:
a) #include
b) arraySize = 10; // arraySize was declared const
c) Assume that int b[ 10 ] = {};
for ( int i = 0; i <= 10; i++ )
b[ i ] = 1;
d) Assume that int a[ 2 ][ 2 ] = { { 1, 2 }, { 3, 4 } };
a[ 1, 1 ] = 5;
a) Error: Semicolon at end of #include preprocessor directive.
Correction: Eliminate semicolon.
b) Error: Assigning a value to a constant variable using an assignment statement.
Correction: Initialize the constant variable in a const int arraySize declaration.
c) Error: Referencing an array element outside the bounds of the array (b[10]).
Correction: Change the final value of the control variable to 9 or change <= to <.
d) Error: Array subscripting done incorrectly.
Correction: Change the statement to a[ 1 ][ 1 ] = 5;
You might also like to view...
Which of the following features performs tasks such as replacing fractions or formatting Internet addresses as hyperlinks?
A. AutoFormat B. AutoCorrection C. AutoOption D. TextCorrection
Which phase of the laser printing process melts the toner onto the paper?
A) Exposing B) Developing C) Charging D) Fusing
What will happen if the hub in a 10BaseT network loses power?
What will be an ideal response?
Solve the linear equation. If necessary, answer no solution.
What will be an ideal response?