< previous page page_641 next page >

Page 641
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
int arr[4] = {10, 20, 30, 40};
int index;

for (index = 1; index <= 4; index++)
    cout << ' ' << arr[index];
Instead, the code printed 20 30 40 24835. Explain the reason for this output.
9. Given the declarations
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
int sampIe [8];
int i;
int k;
show the contents of the array sample after the following code segment is executed. Use a question mark to indicate any undefined values in the array.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
for (k = 0; k < 8; k++)
    sample[k] = 10 - k;
10. Using the same declarations given for Exercise 9, show the contents of the array sample after the following code segment is executed.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
for (i = 0; i < 8; i++)
    if (i <= 3)
        sample[i] = 1;
    else
        sample[i] = -1;
11. Using the same declarations given for Exercise 9, show the contents of the array sample after the following code segment is executed.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
for (k = 0; k < 8; k++)
    if (k % 2 == 0)
        sample[k] = k;
    else
        sample[k] = k + 100;
Programming Warm-Up Exercises
Use the following declarations in Exercises 1-8. Assume the data type Boolean already has been definned. You may declare any other variables that you need.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
const int MAX_STUD = 100;  // Max. number of students

Boolean failing [MAX_STUD ];
Boolean passing [MAX_STUD];
int     grade;
int     length;
int     score[MAX_STUD];

 
< previous page page_641 next page >