Click to See Complete Forum and Search --> : problem with return (char) 0


7stud
02-03-2005, 10:59 PM
I have a function that returns zero converted to a char. It seems to me the return value should be the character '0', but when I try to display it using System.out.println(), the zero character doesn't display and a subsequent System.out.println("finish") doesn't display anything either. How come I can't get zero to display?

cross posted here:http://www.sitepoint.com/forums/showthread.php?t=230885

class SomeClass
{

char func()
{
return (char) 0;
}
};

class TestReturn
{
public static void main(String[] args)
{

SomeClass c = new SomeClass();

System.out.println('0'); //output the character zero
System.out.println("start");

for(int i = 0; i < 3; i++)
{
System.out.println(c.func());
}

System.out.println("finish");


}
}


Instead, I get this for output:

---------- java ----------
0
start

Output completed (2 sec consumed)

7stud
02-04-2005, 08:26 AM
Got an answer at the other forum.

ray326
02-04-2005, 12:52 PM
Just so other folks coming here get an answer, too, (char)0 means a character with the numeric value 0, which in ASCII is called NUL. It does not mean '0', which in ASCII would be (char)65.