#include <iostream>
// 指针函数,接受两个整数参数并返回它们的和的指针
int* sumFunction(int a, int b) {
int* result = new int(a + b);
return result;
}
// 普通函数,接受两个浮点数参数并返回它们的乘积
float multiplyFunction(float a, float b) {
return a * b;
}
int main() {
// 调用指针函数
int num1 = 3, num2 = 5;
int* sumPtr = sumFunction(num1, num2);
std::cout << "Sum of " << num1 << " and " << num2 << " is: " << *sumPtr << std::endl;
delete sumPtr;
// 定义函数指针,指向 multiplyFunction
float (*multiplyPtr)(float, float) = multiplyFunction;
float floatNum1 = 2.5f, floatNum2 = 3.5f;
float product = multiplyPtr(floatNum1, floatNum2);
std::cout << "Product of " << floatNum1 << " and " << floatNum2 << " is: " << product << std::endl;
return 0;
}