In a Boolean context such as the condition of a for loop, each expression in C evaluates to true (non-zero) or false (zero).
You want the for loop to terminate, when it reaches the end of the string.
In C, each string is terminated with the character '\0', which is practically 0. So, when the for loop reaches the end of string, *p evaluates to '\0', which is 0, which evaluates to false, which terminates the for loop.