Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why does this compile?

 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


how is (f<c) even compiling? arent they of different types?
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is this because in an arithmetic operation the char will be promoted to float? i think this could be the reason...

please confirm
 
rohan yadav
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think char is internally converted to float or int.
 
Chintan B Shah
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think "widening" happens here and "if" boolean expression would look something like this
if(9<97)

My 2 cents.

Thanks
Chintan.
 
Hiruka Sandev
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Internally a char is a 16 bit unsigned integer. So a char can be used in places where a integer literal could be used.
 
Dejan Miler
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all char is of integer type.
And secondly i agree with Ankur char will be promoted to float.

Dejan.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic