c++ int function pointer code example
Example 1: C++ pointer arithmetic
#include <iostream>
using namespace std;
const int MAX = 3;
int main () {
int var[MAX] = {10, 100, 200};
int *ptr;
ptr = var;
for (int i = 0; i < MAX; i++) {
cout << "Address of var[" << i << "] = ";
cout << ptr << endl;
cout << "Value of var[" << i << "] = ";
cout << *ptr << endl;
ptr++;
}
return 0;
}
Example 2: 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;
}