Function Pointer in C


Function Pointers point to code like normal pointers.

In Functions Pointers, function’s name can be used to get function’s address.

A function can also be passed as an arguments and can be returned from a function.

Declaration

function_return_type(*Pointer_name)(function argument list)

Example

 Live Demo

#include<stdio.h>
int subtraction (int a, int b) {
   return a-b;
}
int main() {
   int (*fp) (int, int)=subtraction;
   //Calling function using function pointer
   int result = fp(5, 4);
   printf(" Using function pointer we get the result: %d",result);
   return 0;
}

Output

Using function pointer we get the result: 1

Updated on: 30-Jul-2019

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements