I am reading a book called head first c and they told me a concept about casting pointers. I understand why I would do it but what I want to know is how to do it? Like what is the syntax?
int compare_names(const void* a, const void* b)
{
const char** sa = (const char**)a;
const char** sb = (const char**)b;
//why would, in the return section, we use normal pointers instead of **?
return strcmp(*sa, *sb);
}
I get that on the left side we are using 2 asterisks because sa
/sb
are pointers to pointers but on the right side, I have absolutely no idea what is going on. Are we making an assignment from pointer to a pointer?
Also please explain everything about the return line.
**One final question I have is when I write the a statement like (char*)a or (int*)a am I making "a" into an integer or a char?**