This is the code:
char *(*strcpy_ptr)(char *dst, const char *src); Pointer to strcpy-like function
And the tutorial says:
Note the parentheses around *strcpy_ptr in the above declaration.
These separate the asterisk indicating return type (char *) from the
asterisk indicating the pointer level of the variable (*strcpy_ptr —
one level, pointer to function).
I’m lost on this – where is the “function pointer” and what is the “pointer level” ?
You are declaring a variable
strcpy_ptr. You want this variable to be a pointer to a function returning achar*. If you did it without the parentheses this way:It would be the prototype of a function that returns a
char**– not what you want. The parentheses are to group one star with the variable, and seperate the star from the return type.Remember that pointers are declared like this:
Where
Tis some type. The more stars you add, the more levels of indirection you add before you finally get to the actualT. Sochar **cwould be a pointer to a pointer to achar. It’s the same thing for function pointers:Tischar*, and*varmust be seperated by parentheses, because C is ignorant of white space. C just added a little extra syntax to specify what kind of and how many arguments the function takes that is pointed to by the pointer. This is just part of the way C works.