What is the difference between the two declarations in case of foo
's arguments? The syntax in the second one is familiar to me and declares a pointer to function. Are both declarations fully equivalent?
void foo(int(int));
void foo(int(*)(int));
The following is the syntax for the declaration of a function pointer: int (*FuncPtr) (int,int);
Declare a variable x of the integer datatype. Print the value of varisble x. Declare a pointer p of the integer datatype. Define p as the pointer to the address of show() function.
Function pointers in C need to be declared with an asterisk symbol and function parameters (same as function they will point to) before using them in the program. Declaration of function pointers in C includes return type and data type of different function arguments.
The * refers to the return type of the function, which is void * .
They are equivalent as long as int(int)
and int(*)(int)
are used in function parameter lists. In function parameter list the int(int)
is automatically adjusted by the language to mean int(*)(int)
.
It is the same adjustment mechanism that makes int []
parameter declaration equivalent to int *
parameter declaration.
Outside of this specific context int(int)
and int(*)(int)
mean two different things.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With