Can I conclude that bool can even analyze strings as true or false? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Can I conclude that bool can even analyze strings as true or false?

https://www.sololearn.com/discuss/550449/?ref=app The following problem I had the day before yesterday was solved only when I interchanged the bool and the int parameters in the first constructor... Thus I think that the bool data type was also reading strings and analyzing it, as the 1st constructor was being invoked... So, why is this happening? How does bool analyze a string as true or false? Is it based on size? Or on first character?

22nd Jul 2017, 4:37 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
4 Answers
+ 11
any value that is not 0 is considered true.
22nd Jul 2017, 4:40 AM
jay
jay - avatar
+ 5
@jay Wow. Even an empty string is shown as true...
22nd Jul 2017, 5:42 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 4
@Jay Ok. So what string can be rendered false?
22nd Jul 2017, 4:43 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar