+ 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.
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;
}