Created
January 28, 2018 15:25
-
-
Save ksjgh/43b633de872cf54dbf07dac21fef6bf0 to your computer and use it in GitHub Desktop.
function pointer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*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