Function Pointer in C
0 902
A function pointer is like a note that holds the location of a function instead of holding data.
A function pointer is a special kind of pointer that stores the address of the function.
It allows you to call a function indirectly through the function.
The function pointer holds the memory address of the function instead of the data.
Syntax of Function Pointer in C
Return type(*function pointers variable name)(parameters);Example:
int(*func)(int a,int b);
Program for Function pointer in C
// Program for Function pointer in C
#include<stdio.h>
// Function declarations
int add(int A, int B);
int main() {
// Declare a function pointer for functions taking two ints and returning int
int (*C)(int, int);
C = add;
int sum = C(5, 3);
printf("Result of add function: %d\n", sum);
return 0;
}
int add(int a, int b) {
return a + b;
}
Output:
Result of add function: 8
Share:



Comments
Waiting for your comments