gpt4 book ai didi

c - typedef with function this 被问到但无法理解?

转载 作者:行者123 更新时间:2023-11-30 17:29:53 25 4
gpt4 key购买 nike

嗨,我无法弄清楚函数指针在下面的代码中是如何定义的。请任何人解释一下

 #include<stdio.h>
typedef int(*fp)(int,int) ; this is typedef with function pointer i m unable to figure out?
int sum (int,int);
int main()
{
fp p,q; // p, q become function pointer too how?
p=sum;
printf("%d\n",p(20,10));
}
int sum(int i,int j)
{
return(i+j);
}

最佳答案

嗯,没什么好理解的。您定义一个新类型 int(*fp)(int, int)。这不是函数指针,而是函数指针类型。将 fp 与 float、int 或任何其他基本类型进行比较。然后声明上述类型的 p 和 q 并将相同类型(隐式)的函数 sum 分配给 p。

关于c - typedef with function this 被问到但无法理解?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25459546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com