What is the correct way for declaring a pointer to a void function?
void reverseArray(int arraySize, int a[]){
}
One of my many attempts which I think is somewhat correct
void (*reversePtr)(int, int) = &reverseArray;
The second parameter of the function pointer has an invalid type. As the function is declared like
void reverseArray(int arraySize, int a[]);
then a pointer to the function will look ,like
void ( *reversePtr )( int, int[] ) = reverseArray;
or like
void ( *reversePtr )( int, int * ) = reverseArray;
Take into account that there is no need to use the address of operator in the initializer expression like &reverseArray. It is enough to write just reverseArray because a function designator used in expressions is converted to pointer to its type.
For example you could even write
void ( *reversePtr )( int, int * ) = *****reverseArray;
or
void ( *reversePtr )( int, int * ) = *&*&*&*&*&reverseArray;
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