CIS 181 Intro to Comp Sci
Class 14, March 24, 2005

ASSIGNMENT:

Read: D&D, through p. 370 (through 5.12), pp. 404-411 (through 6.4)

Exercises due Tuesday, March 24: take a look at Assignment 3!


UNIX TIP OF THE DAY:

You can change lots of things about the look of Unix in your .cshrc file. For example, you might make your prompt the machine name, the time, or a directory listing. Take a look in your default .cshrc file and see if you can figure out how to change your prompt to something else. Feel free to look in my .cshrc file for more ideas! It should be readable.


ANOTHER UNIX TIP OF THE DAY:

Want to see if your friends are logged on to the network?
who -- will list the current users of your machine
rwho -- will list the current users of any machine on the network


TODAY'S TOPICS
  1. Call-by-reference using pointer variables (how did we do this before??  see p. 212 figure 3.20)-- see CubeByValue (from book), CubeByReference using a pointer parameter (from book).
  2. Using const qualifier with pointers. Even when using call-by-value, using const can clarify your program. Four options exist when a function takes a pointer the header may use const:

    fn_name(type * typePtr) -- neither the data nor the pointer are constants so both may be changed within the body of the function see: $CLASSHOME/deitel-files/examples/ch05/fig5_10.cpp

    fn_name(const type * typePtr) -- here the data is constant, but the pointer may be changed within the function, see: $CLASSHOME/deitel-files/examples/ch05/fig5_11.cpp Note -- only the data being pointed to is being passed call-by-reference, the pointer itself is passed call by value. Changes to it are not reflected in the calling program. See: $CLASSHOME/deitel-files/examples/ch05/fig5_11.cpp

    fn_name(type * const typePtr) -- here the data can be changed, but the pointer itself cannot be (but see the note above anyway!). This SHOULD be the way the swap function in figure 5.15 was implemented. To see it in use, see the file: $CLASSHOME/deitel-files/examples/ch05/const-5-15.cpp Note -- if this were an array, then having a const pointer would mean that array subscript notation would need to be used to access the array elements. (That is what is the case in the bubble sort -- so the updated file has const there too!)

    fn_name(const type * const typePtr) -- here the data and the pointer are both constants. Notice how the program in figure 5-11 can be rewritten this way -- using array subscript notation instead of pointer-incrementing. See the file: $CLASSHOME/deitel-files/examples/ch05/const-const-5-11.cpp

  3. Pointer arithmetic and sizeof (see pointers.cc)
  4. Relationship between arrays and pointers.
  5. Quick intro to a couple of string manipulation functions -- strings are just character arrays with a null character in them