+ 1

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,

Can someone give me example for this..with a code☝☝☝

4th Feb 2019, 9:33 AM
Manav Malhotra
Manav Malhotra - avatar
1 Antwort
+ 6
Here you go ... #include <iostream> int main() { bool bool_var = true; int i = bool_var; // boolean to int std::cout << "i = " << i << "\n"; bool_var = false; i = bool_var; std::cout << "i = " << i << "\n"; // int to boolean i = 0; bool_var = i; std::cout << "bool_var = " << std::boolalpha << bool_var << "\n"; i = 42; // anything non zero means true bool_var = i; std::cout << "bool_var = " << std::boolalpha << bool_var << "\n"; return 0; } Hth, cmiiw
4th Feb 2019, 10:19 AM
Ipang