C++ Chapter 7: Arrays

  1. An array behaves like a list of variables with a uniform naming mechanism that can be declared in a single line of simple code.
  2. The individual variables that make up the array are referred to as indexed variables, though they are sometimes called subscripted variables or elements of the array.
  3. The number in square brackets is called an index or a subscript.
  4. The number of indexed variables in an array is called the declared size of the array, or sometimes simply the size of the array.
  5. When an index expression evaluates to some value other than those allowed by the array declaration, the index is said to be out of range or simply illegal.
  6. An array can be initialized when it is declared.
  7. When initializing the array, the values for the various indexed variables are enclosed in braces and separated with commas.
    i.e.
    int children[3] = {2, 12, 1};
  8. If you initialize an array when it is declared, you can omit the size of the array and the array will automatically be declared to have the minimum size needed for the initialization values.
    int b[] = {5, 12, 11};
    is equivalent to:
    int b[3] = {5, 12, 11};
  9. You can use both array indexed variables and entire arrays as arguments to functions.
  10. An indexed variable can be an argument to a function in exactly the same way that any variable can be an argument.
  11. A function can have a formal parameter for an entire array so that when the function is called, the argument that is plugged in for this formal parameter is an entire array.
  12. A formal parameter for an entire array is neither a call-by-value parameter nor a call-by-reference parameter; it is a new kind of formal parameter referred to as an array parameter.
  13. When an array is used as an argument in a function call, any action that is performed on the array parameter is performed on the array argument, so the values of the indexed variables of the array argument can be changed by the function.
  14. An array parameter that is modified with a const is called a constant array parameter.
  15. An array can be used to store and manipulate a collection of data that is all of the same type.
  16. The indexed variables of an array can be used just like any other variables of the base type of the array.
  17. A for loop is a good way to step through the elements of an array and perform some program action on each indexed variable.
  18. The most common programming error made when using arrays is attempting to access a nonexistent array index.
  19. Always check the first and last iterations of a loop that manipulates an array to make sure it does not use an index that is illegally small or illegally large.
  20. An array formal parameter is neither a call-by-value parameter nor a call-by-reference parameter, but a new kind of parameter.
  21. An array parameter is similar to a call-by-reference parameter in that any change that is made to the formal parameter in the body of the function will be made to the array argument when the function is called.
  22. The indexed variables for an array are stored next to each other in the computer's memory so that the array occupies a contiguous portion of memory.
  23. When the array is passed as an argument to a function, only the address of the first indexed variable (the one numbered 0) is given to the calling function. Therefore, a function with an array parameter usually needs another formal parameter to type int to give the size of the array.
  24. When using a partially filled array, your program needs an additional variable of type int to keep track of how much of the array is being used.
  25. To tell the compiler that an array argument should not be changed by your function, you can insert the modifier const before the array parameter for that argument position.
  26. An array parameter that is modified with a const is called a constant array parameter.
  27. If you need an array with more than one index, you can use a multidemensional array, which is actually an array of arrays.
Author
senator77
ID
141001
Card Set
C++ Chapter 7: Arrays
Description
C++ Chapter 7: Arrays
Updated