Lecture Notes for Introduction to Computer Science II
7 August 2001 - Arrays
- there are no arrays - only pointers
- the expression
a[expr]
is equivalent to the expression *(a +
(expr))
- this is why inside changes to arrays are visible outside
- the name of an array is a constant pointer
- points to the first element of the array
- can't be assigned to
- pointer arithmetic
- you can add or subtract a pointer and an integer - scaled arithmetic
- you can subtract two pointers
- returns the number of elements between the two pointers
- only makes sense if both pointers refer to the same array - but the
compiler doesn't check
- pointer relations
- equal and not equal - do pointers point to the same place (or not)
- other relations also work - only makes sense for same-array pointers
This page last modified on 15 August 2001.