Skip to content

Instantly share code, notes, and snippets.

@ksjgh
Created January 28, 2018 15:25
Show Gist options
  • Select an option

  • Save ksjgh/43b633de872cf54dbf07dac21fef6bf0 to your computer and use it in GitHub Desktop.

Select an option

Save ksjgh/43b633de872cf54dbf07dac21fef6bf0 to your computer and use it in GitHub Desktop.
function pointer
/*Student Playground*/
#include "main.hpp"
#include <iostream>
int add(int a, int b)
{
return a+b;
}
int mul(int a, int b)
{
return a*b;
}
int operation(int a, int b, int (*f_ptr)(int,int))
{
return f_ptr(a,b);
}
int main()
{
int (*f_ptr)(int,int);
int m,n;
m = operation(7,10,add);
n = operation(m,2,mul);
std::cout<<"result =" << n;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment