This is my function:
void printCString(char *s)
{
while (s != nullptr) // printing doesn't stop after ! from passed string.
{
std::cout << *s;
++s;
}
}
and I call it:
char s[]{ "Hello, world!" };
printCString(s);
If I replace stop condition from while block with:
while (*s != '\0')
than it's working well. Can anybody explain me why this behavior?
spoints somewhere in memory. You are checking whetherspoints to memory location zero (more or less). There's no reason why the next memory location after the!of the string should be memory location zero.nullptrfor null character.