I am wondering why the following program compiles fine
#include <iostream> int main() { char a = false; if (!a) { std::cout << "kdjk"; } char b = true; if (!b) { std::cout << "ppp\n"; } return 0; } Output : prints kdjk
Why does assignment of bool value to char compiles without warnings?
trueis1equals toSOH.falseis0equals toNUL.booltype was actually added to the language it also used the fairly flexible implicit type conversions prevalent for other types. This is not a behavior that I like, but it would be a major breaking change to change the rules now, and would break C++'s rather impressive effort to maintain backwards compatibility to earlier C++ standards and C.