In a book I am reading there is a piece of code :
string x;
size_t h=0;
for(const char* s=x.c_str();*s;++s)
h=(h*17)^*s;
Regarding this code, I have two questions:
-
how can
*sbe a condition? what does it mean? -
what does
"h=(h*17)^*s"mean?
Thanks for help!
It means “while the value pointed to by
sis not zero.” C strings are null-terminated, so the last character in the string returned byc_str()will be the null character (\0, represented by all bits zero).It multiplies
hby17thenxors it with the value pointed to bys.