we all know about functions and pointers very well. but what is function pointer ? function pointer is pointer who points to a function.
why we use function pointers? well we use function pointers to increase the execution time of our lovable code.
let's say we have a pointer type integer. int *p,a;
p = &a, above little code tells us that the address of 'a' is now assign to pointer p. hence if int a = 5 then pointer *p which have the address of 'a' and in the address of 'a' we have the value 5 which we initialize earlier. this is the basic concept which all we know about pointer and the same thing regarded to FUNCTION POINTER. initially we take a function like this.
int add (int a, int b) //definition of a funt. add { add = a + b }
now we have add. function.
Now next question which arises is how to assign a pointer to function well we all know about pointer good. then assigning a pointer to a function is nothing just like a cutting a cake.
int (*add_ptr)(); // declaring a function pointer of add. this is how we declared a funct. pointers
next step. add_ptr = add; // here we assign the value of add function to its function pointer which is "add_ptr" inside the main function. now all we have to do is to call our function pointer.
int main() { int *P; // initializing a pointer variable add_ptr = add; // assigning funt. to its funt. pointer. P = (*add_ptr)(); // assigning funt. pointer to pointer varible.