c++ fonksion pointer

#include <iostream>

// Function to add two integers
int add(int a, int b) {
    return a + b;
}

// Function to subtract two integers
int subtract(int a, int b) {
    return a - b;
}

// Function that takes two integers and a function pointer,
// and uses the function pointer to perform an operation on the integers
int performOperation(int x, int y, int (*operation)(int, int)) {
    return operation(x, y);
}

int main() {
    // Declare two integers
    int num1 = 10, num2 = 5;

    // Declare a function pointer for addition
    int (*additionPtr)(int, int) = add;

    // Declare a function pointer for subtraction
    int (*subtractionPtr)(int, int) = subtract;

    // Use the function pointer to perform addition
    int resultAddition = performOperation(num1, num2, additionPtr);

    // Use the function pointer to perform subtraction
    int resultSubtraction = performOperation(num1, num2, subtractionPtr);

    // Output the results
    std::cout << "Result of addition: " << resultAddition << std::endl;
    std::cout << "Result of subtraction: " << resultSubtraction << std::endl;

    return 0;
}