Lecture Notes for Introduction to Computer Science II

19 June 2001 - Array Parameters


  1. the array size is not part of the type

  2. array sizes need not be given in parameter declarations

    1. int pairs(int rank_counts[13])

    2. int pairs(int rank_counts[])

    3. the compiler ignores array sizes in parameter declarations

      1. this compiles without error

        int count(int array[5]) { . . .}
        int array[10];
        count(array);
        

  3. other mechanisms must be used to indicate array size

    1. explicit size parameter

    2. special array-element value - the null byte

  4. arrays passed into a procedure can be modified by the procedure

    1. int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
      f(a);
      if (a[1] == 1) // not necessarily true.
      

    2. the const qualifier prevents array changes

    3. cmd(int count(const int a[], int a_size) { })

  5. overwriting arrays in functions is an especially nasty problem to find and fix


This page last modified on 19 June 2001.