| Author |
need clairifications about char type
|
nada saif
Greenhorn
Joined: Nov 14, 2009
Posts: 8
|
|
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
Joined: Aug 19, 2009
Posts: 46
|
|
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
Joined: Nov 14, 2009
Posts: 8
|
|
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
Joined: Oct 13, 2005
Posts: 32675
|
|
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
Joined: Nov 14, 2009
Posts: 8
|
|
Thanks guys, i really appreciate your sense of cooperation .
Good luck.
Nada
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
|
|
You're welcome
|
 |
Venu Chakravorty
Ranch Hand
Joined: Aug 19, 2009
Posts: 46
|
|
|
you're welcome.
|
 |
jami siva
Ranch Hand
Joined: Oct 16, 2009
Posts: 56
|
|
|
The word of saying 'Thanks' after getting the reply is boosting for the people who post answers.
|
 |
 |
|
|
subject: need clairifications about char type
|
|
|