–Contains address of function
–Similar to how array name is address of first element
–Function name is starting address of code that defines function
§Function pointers can be
–Passed to functions
–Stored in arrays
–Assigned to other function pointers
§Example: bubblesort
–Function bubble takes a function pointer
-bubble calls this helper function
-this determines ascending or descending sorting
–The argument in bubblesort for the function pointer:
int ( *compare )( int a, int b ) tells bubblesort to expect a pointer to a function that takes
two ints and returns an int
–If the parentheses were left out: int *compare( int a, int b )
-Defines a function that receives two integers and returns a pointer to a int





Pointers to Functions:



沒有留言:
張貼留言