#include <iostream>
usingnamespace std;
int main ()
{
int a = 0, b = 1, c = 2;
if ((c % b) + a)
cout << "1st";
elseif ((a % b) + c)
cout << "2nd";
elseif ((b % a) + b)
{
cout << "3rd";
}
else
cout << "4th";
return 0;
}
Given 1 % 0: division by zero is not trapped or handled by C++. Unless you use an OS-specific method to catch it you will get a program crash. (Best to always check that your divisor is non-zero before trying.)
Integral conversions
A prvalue of an integer type or of an unscoped enumeration type can be converted to any other integer type. If the conversion is listed under integral promotions, it is a promotion and not a conversion.
* If the source type is bool, the value false is converted to zero and the value true is converted to the value one of the destination type (note that if the destination type is int, this is an integer promotion, not an integer conversion).
Boolean conversions
A prvalue of integral, floating-point, unscoped enumeration, pointer, and pointer-to-member types can be converted to a prvalue of type bool.
The value zero (for integral, floating-point, and unscoped enumeration) and the null pointer and the null pointer-to-member values become false. All other values become true.
(Since C++11:) In the context of a direct-initialization, a bool object may be initialized from a prvalue of type std::nullptr_t, including nullptr. The resulting value is false. However, this is not considered to be an implicit conversion.
In other words:
1 2 3 4
bool no = 0; // no == false
bool yes = 42; // yes == true
int one = false; // one == 0
int two = true; // two == 1
I didn't hear about that "fact" while having a udemy course of Frank Mitropoulos and while having school classes by former C++ programmer working for school.
Thanks everyone, I think I understand the statement. Thanks for your effort.