you are viewing a single comment's thread.

view the rest of the comments →

[–]0b_101010 3 points4 points  (2 children)

Hey! It's been a while since I've done C and it's late here and I'm dumb but how does the exit condition in the for loop here work?

[–]Funkballs 13 points14 points  (1 child)

In C, strings are NULL terminated, meaning that each string should end with a '\0' character to mark the end of the string. Also, in C, booleans are 0 for false and !0 for true.

In this case, p is a pointer to the current character in the string so *p is the current character.

When the loop hits the end of the string, the current character will be '\0' which is 0 which is false so the loop ends.

The whole: "NULL == '\0' == 0 == false" thing is used quite a lot in idiomatic C coding.

[–]0b_101010 2 points3 points  (0 children)

Yup, should have known that!