• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A simple question about declearation of float

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I came cross a question:
float f=-1;
float f=0x1203;
float f=012;
To my suprised,all is compliation to succeed.
why the primitive type of folat can declear are this way.
Thank u very much.
[ February 19, 2003: Message edited by: frank yang ]
 
Ranch Hand
Posts: 366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Frank,
This is the order or widening
byte--> short--> int-->long-->float-->double
and
char-->int
in your example, float is assigned integer values which is acceptable. An automatic widening of int values into float takes place
but if you say int i = 2.3f , it needs an explicit cast because it is in the oppostie order in the above tree.
so int i = 2.3f //compiler error
int i = (int)2.3f // ok
Sri
 
reply
    Bookmark Topic Watch Topic
  • New Topic