printf function returns number of characters *successfully printed* to console screen.
(You probably know)
'\0' is still a charecter but when it's used as a part of a string it actually terminates string.
Try to run:
You'll get "foo" (not "foo\0bar") as resulting string.
Since you don't actually print a null and use it for indicating end of string, printf will not count it as a printed charecter and will return 0 for an empty string ended with '\0'
This `0` number returned by printf is implicitly typecasted to boolean `false` , causing `else` part to be executed instead of `if` .