1. Friday, 9/18/2009 Notes

    In lecture today, we covered the following topics:

    • review of the memory leak problem and definition of the dangling pointer problem
    • dynamic memory allocation for arrays, and the corresponding delete requirements
    • dynamic memory allocation and deletion for multi-dimensional arrays (requiring loops)
    • pointers as first class types, including their use as parameters and return types
    • how passing a pointer to a variable as a parameter acts like passing the variable by reference
    • how pointer types themselves can be passed by value or passed by reference, and how that effects whether or not the pointer’s value can be changed (what the pointer is pointing to)

    The programs demonstrated today included:

    • copyMe.cpp (dynamic memory allocation, pointer as return type)
    • pbrEmulation.cpp (emulating pass by reference of a variable by passing the pointer to the variable)
    • pbrPointers.cpp (passing pointers themselves with pass-by-value and pass-by-reference)
    • dynamicArrayInFunction.cpp (examples of dynamic allocation and deleting of an array)