What does
int *(cmp)(char*, char*);mean?What is the difference between
char* ptr1;andchar *ptr2;
1 Answer
this
int *(cmp)(char*, char*); is a declaration of a function that has the return type int * and two parameters of the type char *.
You may enclose a declarator in parentheses. So the above function declaration can be also rewritten like
int * ( (cmp)(char*, char*) ); The both declarations are equivalent to
int * cmp(char*, char*); A declaration of a pointer to such a function will look like
int * ( *p_cmp )(char*, char*) = cmp; There is no difference between these declarations
char* ptr1; char *ptr1; char * ptr1;
int *(cmp)(char*, char*);is simplyint *cmp(char*, char*);:cmpis a function that takes two arguments and both of typechar *and returns a pointer toint. 2. No difference. It's matter of choice.char *ptr2;because inchar* ptr2, ptr3;theptr3is not a pointer, it ischar ptr3;cmp(compare?), I'd be inclined to think the signature is actuallyint (*cmp)(char*, char*);, i.e. a pointer to a function which returns anint, as a parameter for aqsort-style comparison function (as explained here). This thread might be useful if you want to see how to write such a function.int a,b,c = 0;when the programmer meant to set all items to zero, not justc.