Lecture Notes for Introduction to Computer Science II

7 August 2001 - Arrays


  1. there are no arrays - only pointers

    1. the expression a[expr] is equivalent to the expression *(a + (expr))

    2. this is why inside changes to arrays are visible outside

    3. the name of an array is a constant pointer

      1. points to the first element of the array

      2. can't be assigned to

  2. pointer arithmetic

    1. you can add or subtract a pointer and an integer - scaled arithmetic

    2. you can subtract two pointers

      1. returns the number of elements between the two pointers

      2. only makes sense if both pointers refer to the same array - but the compiler doesn't check

  3. pointer relations

    1. equal and not equal - do pointers point to the same place (or not)

    2. other relations also work - only makes sense for same-array pointers


This page last modified on 15 August 2001.