0
int main() {if (11 == 11.0) {
        cout << 50 - (50 * 11.0 / 100) <<endl;
        cout << 50 - (50 * 11 / 100) <<endl;}
    return 0;}

// output 44.5

// output 45

can anyone explain this ?

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
  • 2
    As soon as at least one `double` is involved (`11.0` is a constant of type `double`.), the operator `/` becomes a floating point operator. (The other operand is converted to `double` as well as the result.) For integral expressions (i.e. `50 * 11` and `100`), it is an integral division (with a remainder) which results in an integral type. (Actually, it's a bit more complicated: [Arithmetic operators: Conversions](https://en.cppreference.com/w/cpp/language/operator_arithmetic#Conversions).) – Scheff's Cat Apr 15 '21 at 05:38
  • 11 and 11.0 are not the same, they have a complete different byte representation, but they equal because the =-operator makes an effort to behave as expected. The other operators behave differently. – stefaanv Apr 15 '21 at 06:01

0 Answers0