[RESOLVED] 1 is a number or a character.
Just look the following code fragment.
Code:
Console.WriteLine("The number " + '1' + " as a character have int value " +(int)'1' + ".");
Console.WriteLine("The number " + “1” + " as a number have int value " + (int)(1) + ".");
The output is,
Code:
The number 1 as a character has int value 49.
The number 1 as a number has int value 1.
I never use a number as character and got this by mistake one of my application.
What I want to know what, if I use a number (integer value) as a character it holds another integer value. What is the meaning/purpose of that?
Just forget about the casting on code line 2. I put it there to keep similarities between two code lines.
Re: 1 is a number or a character.
Characters are numbers. 49 is the ASCII code for '1'.
Re: 1 is a number or a character.
Ya it is true. But if I'm use a number 1, simply as a character, it hold another int value, 49. Why is that.
Re: 1 is a number or a character.
Because all characters are stored as ASCII and if you cast a char to a numeric type you get its ASCII code.
It works the other way too:
Code:
char c = (char)49;
Console.WriteLine("I has a value: " + c);
By the way, that looks like C#, not C or C++.
Re: 1 is a number or a character.
Thanks, now I got that where I'm going wrong.
By the way, I put this on a wrong place. If you can move it to the right place.