As I know, Boolean is basically a char datatype, one byte, 0x00 or 0x01
That is not the case, the size of bool
type is implementation-defined and is not specified in the C standard, it is usually defined in stdbool.h
as of C99 and is normally something like:
#define bool _Bool
#define false 0
#define true 1
Before that it wasn't even a mandated type. You can say that in some implementations it's equivalent to a single byte, but not always, the specification only requires that bool
is large enough to hold the values 0 or 1 and this ranges from 1 bit to the largest type possible, natively long long
.
What's the best practice to follow?
This is an opinion based question, still, thinking about it, I would advise to use true
/false
because it's a pattern used in pretty much all the languages and it'll surely be easier to understand, I must admit I'm not the best follower of such practice as I often use 0/1.
This is all overrided by your project/company coding practices or guidelines, if that's the case.
Why do both returns work?
In C, any non-zero value is considered to be true
(this includes negative values) in a boolean context, whereas 0 is considered to be false as can be seen in N1570 Committee Draft of April 12, 2011 ISO/IEC 9899:201x:
§6.3.1.2 Boolean type
1 When any scalar value is converted to _Bool, the result is 0 if the value compares equal to 0; otherwise, the result is 1.59)
Footnotes
59) NaNs do not compare equal to 0 and thus convert to 1.