From e81dec857e2e020953efdaa9fbc181c496320d38 Mon Sep 17 00:00:00 2001 From: Luis Granada Date: Sun, 27 Oct 2019 23:57:42 -0500 Subject: [PATCH] pointers to functions example in C++ --- pointers_to_functions.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 pointers_to_functions.cpp diff --git a/pointers_to_functions.cpp b/pointers_to_functions.cpp new file mode 100644 index 0000000..0f192e9 --- /dev/null +++ b/pointers_to_functions.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; +void someFunction(){ + printf("Hello World from C++\n"); +} +void add(int a, int b, void (*callback)(int)){ + int result = a + b; + callback(result); +} +void callback(int n){ + printf("Result: %d",n); +} +int main() { + /* + * functionPointer is a pointer to function someFunction(); + */ + void (*functionPointer)(void) = someFunction; + functionPointer(); + add(5,9,callback); + return 0; +}