Can anyone please explain this with an example? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can anyone please explain this with an example?

If a Boolean value is assigned to an integer, true becomes 1 and false becomes 0. If an integer value is assigned to a Boolean, 0 becomes false and any value that has a non-zero value becomes true.

23rd Sep 2017, 10:02 PM
Adrija Ray Chaudhuri
Adrija Ray Chaudhuri - avatar
1 Answer
+ 4
#include <iostream> using namespace std; int main() { bool ok = true; bool ok2 = false; int x = ok; int y = ok2; cout << x << " " << y << endl; // output -> 1 0 int x2 = 0; int y2 = 917; bool p = x2; // false (0) bool q = y2; // true (1) cout << p << " " << q; // output -> 0 1 return 0; }
23rd Sep 2017, 10:30 PM
Kawaii
Kawaii - avatar