pointer to a function c++ code example
Example 1: Function pointer C++
void one() { cout << "One\n"; }
void two() { cout << "Two\n"; }
int main()
{
void (*fptr)();
fptr = &one;
*fptr();
fptr = &two;
*fptr();
return 0;
}
Example 2: c function pointer
int (*f_ptr)(int);
f_ptr = foo;
int r = f_ptr(v);
f_ptr = &foo;
int r = (*f_ptr)(v);
Example 3: pointers to pointers in cpp
#include <iostream>
using namespace std;
int main () {
int var;
int *ptr;
int **pptr;
var = 3000;
ptr = &var;
pptr = &ptr;
cout << "Value of var :" << var << endl;
cout << "Value available at *ptr :" << *ptr << endl;
cout << "Value available at **pptr :" << **pptr << endl;
return 0;
}