MQL4|Character Type (char)

Usage The character type (char) is used to represent a single character. Unlike other programming languages, MQL4 uses the int type to represent characters. This is because characters are treated as numerical values internally in MQL4.

Size The size of the character type is 4 bytes. This memory size is necessary to represent the character as a numerical value.

Range of Values The range of values for the character type is from 0 to 255. This is based on ASCII codes, allowing the representation of alphanumeric characters and symbols.

Example of Use Below is an example of using the character type. In this example, characters are treated as numerical values to determine whether a specific character has been input and to output a message accordingly.

void OnStart() {
    // Define characters as numerical values
    int charA = 'A';
    int charB = 'B';

    // Determine if a specific character has been input
    if (charA == 65) {
        Print("Character A has been input.");
    }

    if (charB == 66) {
        Print("Character B has been input.");
    }
}

In this code, the character type is used in the following steps:

  1. Characters ‘A’ and ‘B’ are defined as their respective ASCII codes, 65 and 66.
  2. The if statement is used to determine if character ‘A’ has been input. Since the ASCII code for ‘A’ is 65, a message is output if charA equals 65.
  3. Similarly, the if statement is used to determine if character ‘B’ has been input, and a message is output if charB equals 66.

Thus, the character type is used to treat single characters as numerical values. It is useful in scenarios where character manipulation or determination is required.