Pointer to functions

Home / C Programming / Pointer to functions

Pointer to functions


In C, you can use pointers to functions to store the address of a function and call that function indirectly through the pointer. This provides flexibility and allows you to pass functions as arguments to other functions or return functions from functions.

Here's how you can declare, initialize, and use pointers to functions in C:

Declaration of a pointer to a function:

To declare a pointer to a function, you need to specify the function's return type and parameter types. The syntax is as follows:

return_type (*function_ptr_name)(param_type1, param_type2, ...);

For example, to declare a pointer to a function that takes two integers as parameters and returns an integer:

int (*add_function_ptr)(int, int);

Initializing a pointer to a function:

You can assign the address of a function to the function pointer using the function's name without parentheses:


Using pointers to functions as arguments:

You can pass pointers to functions as arguments to other functions, enabling you to implement callback mechanisms and make your code more flexible.


Using pointers to functions in C can be powerful for implementing dynamic behavior, such as selecting different functions at runtime or creating flexible callback mechanisms. However, it's essential to ensure that the function pointer points to a valid function before calling it, as calling through an uninitialized or NULL function pointer can result in undefined behavior.