In function pointers
,
Why is (*fptr)(int a, int b)
is same as (fptr)(int a, int b)
if the function pointer is assigned to add function?
int (*fptr)(int ,int) = add;
while add(int a , int b) returns sum of two numbers.
In function pointers
,
Why is (*fptr)(int a, int b)
is same as (fptr)(int a, int b)
if the function pointer is assigned to add function?
int (*fptr)(int ,int) = add;
while add(int a , int b) returns sum of two numbers.
C doesn't have function objects, so it makes no sense to dereference a function pointer. Therefore, when a function pointer is dereferenced, it is (with some exceptions) immediately turned back into a pointer to function.
n1570 (the final public draft of the current C standard):
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’’.
6.5.2.2 Function calls 5
If the expression that denotes the called function has type pointer to function returning an object type, the function call expression has the same type as that object type, and has the value determined as specified in 6.8.6.4.