Skip to content

Latest commit

 

History

History
38 lines (25 loc) · 793 Bytes

Notes.md

File metadata and controls

38 lines (25 loc) · 793 Bytes

Function pointers

Let's consider a function:

int fun(int x, int y) {
    return x + y;
}

A function is just a piece of code located somewhere in the memory. So, it has its own address, provided by a pointer.

Function type

The function type is a special data type that can contain a function pointer, like fun:

int (*f)(int, int) = fun;

Where:

  • f is the name of the variable.
  • (int, int) are types of parameters of the function. Note that is not required a name for those.
  • fun is the function that we assign to this function type.

typedef

Rename a function pointer:

typedef int (*custom_name)(int, int);

Return to the index