We can clear above problem in two different concept of C
- Working of if( condition ) in C
- Difference of Character & String Literals in C
1. Working of if( condition ) in C
if( condition )
In C Language, if condition works on 0(Zero) and Non-Zero base.
If the result of the given condition is Zero, then C consider that given condition is false.
If the result of the given condition is Non-Zero then C consider that given condition is true.
2. Difference of Character & String Literals in C
In C, String literals are those which enclosed in Double quotation marks (""), while Character literals are those which enclosed in Single quotation marks ('') and minimum length is one character and max length is two character.
Another important point is that in C, if we convert '\0' (null) to int (Integer), then we will get 0(Zero), while we cannot convert "\0" to int implicitly or explicitly. Because "\0" is string while '\0' is character.
And according to the string IF condition working logic, if condition returns 0 or false, it means condition is false; in case of condition returns non-zero, it means condition is true.
So, according to point 1 and 2 finally we can conclude that
if ('\0') printf("\'\0\' != false\n"); //condition becomes false
if ("\0") printf("\"\0\" != false\n"); //condition becomes true