+ 1
explain why ternary return this
can someone explain why there are differences in output between if/else and ternar operator..thanks :). https://code.sololearn.com/cbhsBjdu3ro2/?ref=app
4 Réponses
+ 2
Lily Mea
Not necessary to have b and c same type in ternery operator but if you have different type of b and c and you are assigning to an another variable (in case of String and int or double) then it should be same type otherwise you will get compiler error but in case of double and int you will not get any error because you can assign int value to double.
Check last statement.
https://code.sololearn.com/cBX3Wk239VmP/?ref=app
+ 1
Lily Mea
'A' is a character because it has single quote so if you print 'A' then ASCII value will be print that is why you got input like that 65.0 because a is a type of double.
0
Jazz so do u mean if a?b:c, then b and c must have same type..so thats why it cast int to double?
0
I ᴀᴍ "Tɪᴍᴇ" i see..also, i tried 'A':a and the result = 65.0 .. in this case,'A' was casted to double i guess..so if i do "A":a,then result of a(false) will be String?