| 5 | long product(long a, long b); // Function prototype |
| 6 | |
| 7 | int main() |
| 8 | { |
| 9 | long(*fun_ptr)(long, long) {}; // Pointer to function |
| 10 | |
| 11 | fun_ptr = product; |
| 12 | std::cout << "3 * 5 = " << fun_ptr(3, 5) << std::endl; // Call product() thru fun_ptr |
| 13 | |
| 14 | fun_ptr = sum; // Reassign pointer to sum() |
| 15 | std::cout << "3 * (4+5) + 6 = " // Call sum() thru fun_ptr twice |
| 16 | << fun_ptr(product(3, fun_ptr(4, 5)), 6) << std::endl; |
| 17 | } |
| 18 | |
| 19 | // Function to multiply two values |
| 20 | long product(long a, long b) { return a * b; } |