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

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

$
0
0

First, looking at the two conditions, '\0' is a constant of type integer, which denotes the null character C, which is the same as 0. While "\0" is a string literal, which contains 2 bytes, the one specified and the null terminator byte implicitly added. Being a string literal, the pointer cannot be NULL.

Second, in C, for the condition of if statement, everything non-zero is evaluated as true, and zero is evaluated as false.

According to this rule, it will be clear that '\0' is false, and "\0" evaluated as true.


Viewing all articles
Browse latest Browse all 10

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>