0

What's the answer and Why?

#include <iostream> using namespace std; int main() { float a = 1.1; if(a == 1.1) {cout<<"A";} else if(a==1){cout<<"B";} else{cout<<"C";} return 0; }

7th May 2021, 2:51 AM
Vishal Jadhav
Vishal Jadhav - avatar
2 Antworten
+ 4
Hey Vishal Jadhav Here a=1.1 declared as a "float" and 1.1 is considered "double" by default and Double is greater than float , so output is "C" ! Ex: float a=1.1 is equal to 1.0999999 (not exact , with 7 precision) Double a=1.1 is equal to 1.099999999999999999 (with 16 precision)
7th May 2021, 3:07 AM
Giriraj Yalpalwar
Giriraj Yalpalwar - avatar
0
thank you this really helped
12th May 2021, 3:52 PM
Vishal Jadhav
Vishal Jadhav - avatar