So, in this guide I read that saying
char * terry;
was different from saying
char* terry; //or
char *terry; // FYI: I understand what these two do.
as stated by
“I want to emphasize that the asterisk sign (
*) that we use when
declaring a pointer only means that it is a pointer (it is part of its
type compound specifier), and should not be confused with the
dereference operator that we have seen a bit earlier, but which is
also written with an asterisk (*). They are simply two different
things represented with the same sign.”
However I do not understand why. Perhaps I took the quote the wrong way, now that I have read it once again, but I am still confused. Can anyone tell me if this is wrong or right and why?
Thank you.
No, all three are exactly the same as far as the parser is concerned. People certainly have their reasons for using each style, but there’s not really a “right” way. As an editorial note, I prefer:
What the author of your link is describing is that the
*in the declaration is somehow different from the unary*operator used to dereference a pointer:This potential funny business is actually one of the reasons I prefer the notation I mentioned above – it makes both cases look the same, so there’s no room for confusion.