//something here fills in buf correctly
char * cds = strstr(buf,"some string");
if (cds && cds == buf)
What I don't get in this code is what the && is trying to do there. What is the purpose of && in this example?
I see wind mills
Joined: Jul 03, 2009
Only now have I noticed how simple my question was. Of course the && is the AND logical operator. What happens is that I have been dealing with bit operator (such as &) and was reading the expression of the IF statement as
(cds && cds) == true instead of cds && (cds == true), as if the && would do some operation between cds and itself before doing the comparison.
The statement means "if cds is not the null pointer and cds is equal to buf". The whole first part isn't necessary. You could just as well write: if (cds == buf), because if cds == buf is true, then cds will never be the null pointer anyway.
Note that this only compares the pointers, it does not check if that what cds points to contains the same as what buf contains.