Created
January 10, 2020 23:54
-
-
Save misterpoloy/f9c0550e136f1e61c6ebc7bcb17e4e11 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
// https://www.youtube.com/watch?v=LW8Rfh6TzGg&list=PL2_aWCzGMAwLZp6LMUKI3cc7pgGsasm2_&index=5 | |
#include <iostream> | |
int add(int a, int b) { | |
return a + b; | |
} | |
int main() { | |
int c; | |
int (*p)(int, int); // the signature values must coinicde. | |
p = &add; // p = add // Derefference the function name | |
c = (*p)(2, 3); // p(2,3) // Casting value and using function. | |
std::cout << "The sum is: \n" << c << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment