// program to demonstrate passing pointers to functions as function arguments

#include <iostream>
using namespace std;

void 
a(int v)
{
    cout << "a(" << v << ") was called" << endl;
}

void 
b(int v)
{
    cout << "b(" << v << ") was called" << endl;
}

void 
c(int v)
{
    cout << "c(" << v << ") was called" << endl;
}

// call() takes a pointer to a function and calls that function
// the passed function pointer must point to a function that 
//      returns void
// 	has a single int argument
void
call(void (*func)(int))
{

    cout << "call() was passed the pointer " << (void *) func << endl;
    func(42);
}

int
main()
{

    cout << "the value of a is " << (void *) a << endl;
    cout << "the value of b is " << (void *) b << endl;
    cout << "the value of c is " << (void *) c << endl;
    cout << endl;

    // a b c (without the ()) are pointers to functions
    // pass pointers to these functions to the function call()
    call(a);
    call(b);
    call(c);
}

