Char: Difference between revisions
mNo edit summary |
InvaderZim (talk | contribs) No edit summary |
||
Line 6: | Line 6: | ||
char anA = 'A'; //Correct | char anA = 'A'; //Correct | ||
At its core, a [[char]] is really just an 8-bit [[integer]], its value ranging from 0 to 255 | 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 [[integer | unsigned]]: | 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 | ||
However, a different keyword, ''signed'' may be applied to it in order to allow negative values to be stored, but the greatest absolute value it can hold will be cut in half. | |||
signed char smallInteger = 238; //Wrong | |||
signed char smallInteger = 72; //Ok! | |||
signed char smallInteger = -96; //Ok! | |||
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. | 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 09:16, 11 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
However, a different keyword, signed may be applied to it in order to allow negative values to be stored, but the greatest absolute value it can hold will be cut in half.
signed char smallInteger = 238; //Wrong signed char smallInteger = 72; //Ok! signed char smallInteger = -96; //Ok!
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.