• 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

char and int

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,all:

about c+=i, it compile ok, and print c(not a).
and if change it to c=c+i, then compile error!
Need help!

Thanks in advance.
Roger
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
+= will do an automatic cast, so the result will be casted to type char. Therefore, compile fine.
But if just c = c + i, since numerical expressions always result in at least an int-sized result, so it can't comile.
It can compile, if you change it to c = (char)(c + i)

Regards
Anthony Yip
 
Roger Zhao
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anthony,


+= will do an automatic cast, so the result will be casted to type char. Therefore, compile fine.


I did not know this point before. Nice of u! Thanks!
reply
    Bookmark Topic Watch Topic
  • New Topic