Function Pointer in C

CServer Side ProgrammingProgramming

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
raja
Published on 18-Jun-2019 17:56:36
Advertisements