Char

Updated: 08/08/2017 by Computer Hope

CharacterThe abbreviation char is used as a reserved keyword in a number of programming languages, such as C, C++, C#, and Java. It is short for character, which is a data type that holds one character (letter, number, etc.) of data. For example, the value of a char variable could be any one-character value, such as 'A', '4', or '#'.

Also, other languages that do not have char as a data type may use the abbreviation for certain methods that are used with string values. For example, JavaScript has methods such as charAt() and charCodeAt() that return values pertaining to the calling string. The charAt() method, for instance, returns a string containing one character, which is the character at the location given as a parameter to the function. Running the following code would alert the value of the character at position 2 within the string (starts from 0 rather than 1):

mystring = "computer hope";
window.alert(mystring.charAt(2));

The above code would send an alert with the text m, since c is at the 0 position, o is at the 1 position, and m is at the 2 position.

Character, Programming terms