/* */ Click to Join Live Class with Shankar sir Call 9798158723

Pointer with function in C++ ?

Function pointer in C++ is very useful as it can be passed as a parameter to a different function, thus making the functionality of callbacks easy to implement in C++.Where void is the function’s return type. *fun_ptr is a pointer to a function that takes one int argument. It’s as if we are declaring a function called *fun_ptr which takes int and returns void.

Q.) W.A.P to initialize pointer with function.
#include < iostream>  
using namespace std;  
int add(int a , int b)  
    return a+b;  
int main()  
 int (*funcptr)(int,int);  // function pointer declaration  
 funcptr=add; // funcptr is pointing to the add function  
 int sum=funcptr(5,5);  
 std::cout << "value of sum is :" << sum<< std::endl;  
  return 0;