Indeed, the key aspect here is the return type of the ternary expression, which is determined by the possible types of the operands. In this case, even though the boolean expression involves doubles, the ternary operator considers the common type compatible with both branches, which is float because float can accommodate both 12_456 and 12456.02f. This is why the result is float and not double.
The answer is the letter D, analyzing the expression, it returns a false, so it returns 124_56.02f (remembering that the _ does not separate the decimal place, it only separates the number, it only serves to help reading) so when adding 12456.02 + 1024 = 13480.02
Correct answer : C - 13480.0
float var1;
if(12_345.01 >= 123_45.00){
var1 = 12_456;
}else{
var1=124_56.02f
}
=> the condition is true : 12345.01 > 12345.00 => var1 = 12_456 which means 12456 (The underscore is useful just for the readability).
Then var 2 = var1 + 1024;
=> var 2 = 13480 => Output: 13480.0.
this is a tricky question. the boolean statement is double and double doesn't fit inside the float. Looks like false/true return type matters here, not data type inside the boolean expression.
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
EmilioDeBaku
Highly Voted 2 years, 5 months agoamit_lad88
Most Recent 3 days, 20 hours agoManuTov
2 months, 1 week agoRAADEL3IMLAK
10 months, 1 week agocarloswork
1 year, 1 month agoUAK94
1 year, 2 months agoiSnover
1 year, 2 months agoAysegul
2 years, 5 months agoWinston123
1 year, 6 months agoJongHwa
2 years agoSSJ5
2 years, 8 months agoP_Riya
2 years, 10 months agoalain001
3 years, 1 month agobabobobina
3 years, 2 months agokob4yashi
3 years, 2 months agoHarid
3 years, 3 months agohotuya
3 years, 3 months agosai9999
3 years, 4 months agokh_ism
3 years, 5 months ago