main resources links contact

Recitation 21b: Tries

Very much relevant to question 4 on exam 2, a quick reminder of the behavior of modifying arguments passed into functions. C/C0 is pass by value, meaning that a function gets a copy of a variable and that modifying that variable inside the function has no effect after that function returns to the calling function. This generally makes perfect sense when we're discussing small types, like ints, but becomes confusing in the context of pointers. The pointer itself is just a value that holds an address. Like an int, modifying it won't do anything after the function returns. However, modifying the data being pointed two will be evident as a side effect of the function call that will remain changed after the function returns. The key here is that you will be dereferencing and modifying the same block of memory that is seen outside of the function call. So, for the exam question, just changing the pointer itself accomplished nothing--you need to dereference the pointer and change the data being pointed to. Refer to these examples.

If you have any comments or see any errors, please let me know.