UrbanPro
true

Take BSc Tuition from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

C++: Passing A Function As an Argument

Ashutosh Singh
23/12/2017 0 0

#include
using namespace std;

int sum(int a,int b)
{
   return a+b;
}
void f2(int (*f)(int,int),int a,int b) //'*f' is a POINTER TO A FUNCTION whose RETURN TYPE is                                                           //'int' and arg type (int,int)  . Here, '*f' is FORMAL PARAMETER
{                                                                
  cout<<sum(a,b)<<endl;
}
int main()
{   int (*p1)(int,int)=∑          //Here, '*pf1' is ACTUAL PARAMETER
    f2(sum,10,20);                         //NAME OF A FUNCTION IS ITSELF A POINTER TO ITSELF
    f2(p1,20,79);
    return 0;

}

0 Dislike
Follow 3

Please Enter a comment

Submit

Other Lessons for You

C++: Array As Function Argument
Array as Function Argument: C++ #include using namespace std; void f1(int a, int size) //A user-defined function which takes an 'int array' as arguments { for(int i=0;i<size;i++) { ...

Super-Market Billing Console Application
#include using namespace std; int main() { int n=0; float T=0; cout<<"Welcome to Yashtosh Mart !\n"<<endl; cout<<"Type total number of items bought"<<endl; cin>>n;...

Passing A 'Function' As A argument To Another Function: C++
#include using namespace std; int sum(int a,int b) { return a+b; } void f2(int (*f)(int,int),int a,int b) //'*f' is a POINTER TO A FUNCTION whose RETURN TYPE is ...

Looking for BSc Tuition ?

Learn from Best Tutors on UrbanPro.

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for BSc Tuition Classes?

The best tutors for BSc Tuition Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Take BSc Tuition with the Best Tutors

The best Tutors for BSc Tuition Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more