CITS2002 Systems Programming |
← prev | next → | CITS2002 | CITS2002 schedule | |||
Functions with pointer parametersWe know that pointers are simply variables.We now use this fact to implement functions that receive pointers as parameters. A pointer parameter will be initialized with an address when the function is called. Consider two equivalent implementations of C's standard strlen function - the traditional approach is to employ a parameter that "looks like" an array; new approaches employ a pointer parameter:
In this example, strp traverses the null-byte terminated character array (a string) that was passed as an argument to the function. We are not modifying the string that the pointer points to, we are simply accessing adjacent, contiguous, memory locations until we find the null-byte.
CITS2002 Systems Programming, Lecture 11, p10, 26th August 2024.
|