Section 7.2 Check Point Questions12 questions 

7.2.1
How do you declare an array? What is the difference between an array size declarator and an array index?
7.2.2
How do you access elements of an array? Can you copy an array a to b using b = a?
7.2.3
Is memory allocated when an array is declared? Do the elements in the array have default values? What happens when the following code is executed?
int numbers[30];
cout << "numbers[0] is " << numbers[0] << endl;
cout << "numbers[29] is " << numbers[29] << endl;
cout << "numbers[30] is " << numbers[30] << endl;
7.2.4
Indicate true or false for the following statements:
(a) All the elements in an array are of the same type.
(b) The array size is fixed after it is declared.
(c) The array size declarator must be a constant expression.
(d) The array elements are initialized when an array is declared.
7.2.5
Which of the following statements are valid array declarations?
(a) double d[30]; 
(b) char[30] r;
(c) int i[] = (3, 4, 3, 2);
(d) float f[] = {2.3, 4.5, 6.6};
7.2.6
What is the array index type? What is the smallest index? What is the representation of the third element in an array named a?
7.2.7
Write C++ statements to do the following:
(a) Declare an array to hold 10 double values.
(b) Assign value 5.5 to the last element in the array.
(c) Display the sum of the first two elements.
(d) Write a loop that computes the sum of all elements in the array.
(e) Write a loop that finds the minimum element in the array.
(f) Randomly generate an index and display the element at this index in the array.
(g) Use an array initializer to declare another array with initial values 3.5, 5.5, 4.52, and 5.6.
7.2.8
Given int temp[10], what is temp[10]?
7.2.9
Identify and fix the errors in the following code:
1  int main()
2  {
3    double[100] r;
4
5    for (int i = 0; i < 100; i++);
6      r(i) = rand() % 100;
7  }
7.2.10
What is the output of the following code?
int list[] = {1, 2, 3, 4, 5, 6};

for (int i = 1; i < 6; i++)
  list[i] = list[i - 1];

for (int i = 0; i < 6; i++)
  cout << list[i] << " ";
7.2.11
What is the output of the following code?
int list[6] = {1};
cout << list[1] << endl;
7.2.12
A student wrote the following code to assign the input integers to an array and displays the number of the elements in the array. But the code is wrong. Why?
#include <iostream>
using namespace std;

int main()
{
  int arr[100];
  int n = 0;
  int times = 1;
  int temp; // This line is wrong
  cout << "Enter the integers (enter 0 to end the input): ";
  for (int i = 0; temp != 0; i++) {
    cin >> arr[i];
    temp = arr[i];
    n++;
  }
  cout << "The number of integers entered except 0 is " << n - 1 << endl;
  return 0;
}