Hello.
You can study function pointers using typeef.
As I studied the usage example, there is a source like below.
What I'm curious about is what is the return data type of the abc function?
And return (test) NULL; why do you write this part like this?
typedef int (*test)(int, char **);
test abc(char *argv)
{
return (test)NULL;
}
int main(int argc, char **argv)
{
test b;
b = abc(argv[1]);
return 0;
}
The return type of abc()
is a function pointer.
More specifically, returns the address of the function with the return type int and int and char** as parameters.
return (test)NULL;
has the same meaning as returnNULL;
.
They don't cast, but they work the same way.
It seems that the author tried to force the casting because he thought that using NULL
as the function address would cause a compilation error.
© 2024 OneMinuteCode. All rights reserved.