Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need clairifications about char type

 
nada saif
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ,

I found a strange code i couldn't understand , will be great if any can explain how Java compiler translate it






Output is 15


my Questions are

1- can we use char as number??
2- what is the difference the example above between line 5 ,6


Thanks in advance

Nada


 
Venu Chakravorty
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. 'char' is actually a 16-bit unsigned 'int'
2. in line 5 there is an implicit cast, in line 6 you have to cast the resulting 'int' to a
'short'
 
nada saif
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you venu ,

But how char is an integer , i am lost ..
can you elaborate in this point .. or post some useful URLs..


Bests,


Nada
 
Campbell Ritchie
Sheriff
Pie
Posts: 50196
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java™ Language Specification. That's the link. It will (I hope) tell you that the char type is an unsigned integer type.

Try this:
 
nada saif
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys, i really appreciate your sense of cooperation .



Good luck.

Nada
 
Campbell Ritchie
Sheriff
Pie
Posts: 50196
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Venu Chakravorty
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you're welcome.
 
jami siva
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The word of saying 'Thanks' after getting the reply is boosting for the people who post answers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic