Chapter

Function Pointers

From ComputerScienceOne by Dr Chris Bourke

Concepts

  1. What is a function pointer and how is it declared?

    "Now that we have comparator functions to order elements, we need a way of passing a comparator to a generic search or sort function so that it can be used by that function. To achieve this in C, we u

  2. How do callbacks make C functions more generic?

    "The main use for function pointers is so that references to functions can be passed as parameters to other functions. The passed function is known as a callback. This gives us the ability to write a

  3. How can pointer arithmetic and comparators implement a generic getMax()?

    "There are a couple of issues here that we have to deal with. When working with generic void * pointers in C and using arrays, you cannot simply index using the usual 0, 1, 2, etc. indices. Recall tha

  4. How are generic getMax() functions used with integers and structures?

    "Suppose we have an array of integers and the cmpInt() comparator function above. We can use our getMax() function as follows.\n\nint arr[] = {8, 2, 9, 10, 4, 2, 2, 5, 6, 7};\n\nint maxIndex = getMax(

Function Pointers | ComputerScienceOne | Bifalgorithm | Bifalgorithm