Char: Difference between revisions
InvaderZim (talk | contribs) No edit summary |
mNo edit summary |
||
Line 1: | Line 1: | ||
[[category:variables]] | [[category:variables]] | ||
A '''character''' is, programmatically, one ASCII number value used to represent a keyboard character('a', 'x', '1', '6', 'ê'). This variable is declared by the name char, and its value must be surrounded by apostrophes: | A '''character''' is, programmatically, one ASCII number value used to represent a keyboard character('a', 'x', '1', '6', 'ê'). This variable is declared by the name [[char]], and its value must be surrounded by apostrophes: | ||
char anA = A; //Wrong | char anA = A; //Wrong | ||
Line 6: | Line 6: | ||
char anA = 'A'; //Correct | char anA = 'A'; //Correct | ||
At its core, a | At its core, a [[char]] is really just an 8-bit [[integer]], its value ranging from 0 to 255. | ||
In fact, if you require a [[integer]] to store a very small value, a '''character''' can be used for this purpose, but it is important to remember that if you wish to use a | In fact, if you require a [[integer]] to store a very small value, a '''character''' can be used for this purpose, but it is important to remember that if you wish to use a [[char]] for this purpose that they are by definition [[integer | unsigned]]: | ||
char smallInteger = 127; //Ok! | char smallInteger = 127; //Ok! | ||
char smallInteger = -23; //Wrong | char smallInteger = -23; //Wrong | ||
This is why when assigning a | This is why when assigning a [[char]] an ASCII number value you must use apostrophes, so that the compiler know to convert that keyboard character into its 8-bit ASCII value. | ||
[[String]]s are [[array]]s of, or [[pointer]]s to '''Characters'''. These are used more often than characters are in the [[Source Engine]]. | [[String]]s are [[array]]s of, or [[pointer]]s to '''Characters'''. These are used more often than characters are in the [[Source Engine]]. |
Revision as of 21:11, 7 August 2005
A character is, programmatically, one ASCII number value used to represent a keyboard character('a', 'x', '1', '6', 'ê'). This variable is declared by the name char, and its value must be surrounded by apostrophes:
char anA = A; //Wrong char anA = "A"; //Wrong char anA = 'A'; //Correct
At its core, a char is really just an 8-bit integer, its value ranging from 0 to 255. In fact, if you require a integer to store a very small value, a character can be used for this purpose, but it is important to remember that if you wish to use a char for this purpose that they are by definition unsigned:
char smallInteger = 127; //Ok! char smallInteger = -23; //Wrong
This is why when assigning a char an ASCII number value you must use apostrophes, so that the compiler know to convert that keyboard character into its 8-bit ASCII value.
Strings are arrays of, or pointers to Characters. These are used more often than characters are in the Source Engine.