I have the following function which is part of the Trie structure implementation:
int alpha_char_strlen (const AlphaChar *str) {
const AlphaChar *p;
for (p = str; *p; p++) ;
return p - str;
}
Can any one help me and explain how does the condition for the for loop hold, and precisely what is the condition in this case?
Note: AlphaChar is simply a typedef with unsigned int type and the function counts the AlphaChar characters.
The condition
*pis identical to*p != 0(if*pis of a primitive type). That is, you keep incrementing the pointerpuntil it points to a zero. In other words, you treatstras the pointer to a zero-terminated array.