# Pointer to function

Until now, we used pointers that point to values. We can also point to functions.

## Birthday collage analogy continued

If we stay in the birthday collage analogy in {numref}`advantage-of-pointers`:

You have the collage in your room. You ask your friends to write the design instructions on a paper and they must *assume* that the collage has 5 columns. Each friend can describe, e.g., put my photo and message to the next free cell. Then you collect these recipes and execute them in your room.

## Declaration & Usage

:::{literalinclude} ../code/function_pointer.c
:language: c
:name: function-pointer-declaration-and-usage
:::
:::{literalinclude} ../code/function_pointer.txt
:language: text
:::

## Practical example

To implement the `map` which applies a function on all elements of an array in problem {ref}`cryptography`:

:::{literalinclude} ../code-prj/crypto/src/caesar.c
:language: c
:start-at: typedef char (*Func)
:::

:::{activity} Applying arithmetic operations using an array of functions
Start with [the example above](function-pointer-declaration-and-usage) and create an array of function pointers called `ops`. Then iterate over the functions and apply the operations one after another on the `n`.

Hint: You can declare and initialize an array like this:

```c
int (*ops[])(int) = {inc, square, inc, inc}; // Array of SIZE functions
```
:::