第30440题 单选题
以下C++代码中,函数指针p的正确定义及对应运行结果是?

现有C++代码如下:

#include <iostream>
using namespace std;
int add(int a, int b) {
    return a + b;
}
int main() {
    // 此处定义函数指针p指向add函数,并执行调用
    cout << p(2,3) << endl;
    return 0;
}
A

定义为int (*p)(int,int) = &add;,程序输出5

B

定义为int *p(int,int) = add;,程序输出5

C

定义为(*int)p(int,int) = add;,程序输出5

D

定义为int (*p)() = add;,程序输出5

程序运行统计
暂无判题统计
提交0次 正确率0.00%
答案解析