This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Options are : 1)Code will fail to compile 2)It will print d 3)It will print c 4)It will print b 5)It will print a Ans : 5)It will print a I tried running the program , it prints "a" I feel that the statement(i=f) is not correct and even c++ is wrong? Am i right? A bit confused since I cannot understand how are we getting such an output?? Any suggestions?
The expressions are correct. When "if (i == f) c++;" is evaluated ,i is converted to float and so 5.0 . As 5.0 != 5.5 ,C++ is not evaluated when"if (((int) (f + d)) == ((int) f + (int) d)) c += 2;" f+d is added to get a double value 9.3 which is casted to int and result is 9 . (int)f =5 + (int)d= 3 and the result will be 8. 9!= 8 so rest of the expression is not evaluated so the answer is 'a'. hope this explains.