+ 3

What happens when i insert a random number to a bool variable?

Hello When i create a bool x and then input cin x, what happens when i input a number which is not 0 or 1? Example: bool x; cin >> x; cout <<x; What will be the output for: - 8 - 1 or - 0 ??? https://code.sololearn.com/cr7g6EHxq1ZY/?ref=app

3rd Feb 2018, 10:00 AM
Rambo Schweiz
Rambo Schweiz - avatar
3 odpowiedzi
+ 3
A boolean in C++ will be false only if it is 0. Anything else results in a one.
3rd Feb 2018, 10:23 AM
Joseph
+ 2
Thank you!!!
3rd Feb 2018, 12:56 PM
Rambo Schweiz
Rambo Schweiz - avatar
+ 1
yes because the compiler can understand only 0 and non zero.zero means true and any non zero number means false
11th Feb 2018, 3:49 AM
Shridhar Rai
Shridhar Rai - avatar