Logical operator | Sololearn: Learn to code for FREE!


Logical operator

#include <iostream> using namespace std; int main() { double a=0.1; double b=0.2; double c=0.3; cout<<(a+b==c); return 0; } Why is the result 0,bros ? I think the output is 1 because all variables are double type.


7/23/2020 4:06:57 AM

Huda Le

2 Answers

New Answer


Samsil Arefeen Ok understood. Le Huu Dai Actually computer returns 0.1 + 0.2 = 0.30000000000004 that's why output is 0. You can get more explaination here.. https://techtalkbook.com/why-0-1-0-2-does-not-equal-0-3/


Many thanks, pro.