在 function pointers
,
为什么是(*fptr)(int a, int b)
与 (fptr)(int a, int b)
相同函数指针是否赋值给add函数?
int (*fptr)(int ,int) = add;
while add(int a , int b) returns sum of two numbers.
最佳答案
说明
C 没有函数对象,因此取消引用函数指针是没有意义的。因此,当函数指针被取消引用时,它(有一些异常(exception))立即变回函数指针。
引用文献
n1570 (当前C标准的最终公开草案):
6.5.3.2 Address and indirection operators
- The unary
*
operator denotes indirection. If the operand points to a function, the result is a function designator; [...]
...
6.3.2.1 Lvalues, arrays, and function designators
- A function designator is an expression that has function type. Except when it is the operand of the
sizeof
operator, the_Alignof
operator, or the unary&
operator, a function designator with type ‘‘function returning type’’ is converted to an expression that has type ‘‘pointer to function returning type’’.
关于c - 函数指针 : why is (*fptr)(6, 7) 与 (fptr)(6,7) 相同,如果函数是 add(int , int ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24508504/