+ 1

Why the output is 7.8 though "a" and "b" is integer ... I think a=5 b=7 and the function return m =7

#include <iostream> using namespace std; int max(int a,int b) { int m; if (a<b) m= b; else m= a; return m; } int main() { double x=5.6 ,y=7.8; cout<<max(x,y); return 0; }

19th Apr 2017, 1:55 PM
Nour Alnaser
Nour Alnaser - avatar
3 odpowiedzi
+ 4
The output is 7 with no doubt, since you cast it to int implicitly.
19th Apr 2017, 2:19 PM
Babak
Babak - avatar
+ 4
I've gotten these results and I think it's up to compiler on how to deal with implicit type casting. MS Visual C++ ==> 7 C4Droid. ====> 7.8 SoloLearn compiler ==> 7.8 online codeChef =====> 7.8 online webCompile ===> conversation from double to int warning online ideOne =======> 7.8 The only exception here is MS VC++ that shows what we are expected. C4droid and others use gcc, g++, and clang
19th Apr 2017, 3:17 PM
Babak
Babak - avatar
+ 2
@Babak thank you ....🌼🌼
19th Apr 2017, 5:44 PM
Nour Alnaser
Nour Alnaser - avatar