Quantcast
Channel: '\0' evaluates false, "\0" evaluates true - Stack Overflow
Viewing all articles
Browse latest Browse all 10

Answer by user253751 for '\0' evaluates false, "\0" evaluates true

$
0
0

Recall how string literals work in C - "\0" is a character array containing two zero bytes (the one you asked for, and the implicit one at the end). When evaluated for the if test, it decays into a pointer to its first character. This pointer is not NULL, so it's considered true when used as a condition.

'\0' is the number zero, equivalent to just 0. It's an integer which is zero, so it's considered false when used as a condition.


Viewing all articles
Browse latest Browse all 10

Trending Articles