Strings

A string is a sequence of characters such as ab6as88. You indicate to the compiler that a sequence of characters is a string by enclosing it in quotation marks. For instance, "ab6as88" and "hello there" are both strings.

Every character, be it a letter, punctuation, a number or a control character has a numeric value associated with it. These numbers are called the ASCII values of the character. Standard ASCII ranges from 0 to 127. The character 'a' is 97, the character 'b' is 98 etc.

Strings are terminated with the control character \0. This is a single ascii character that appears at the end of a string and indicates that the string is complete. When a string is declared in quotation marks, the termination character is automatically appended to the end of the string.

Single characters are enclosed in single quotes. Control characters count as single characters. 'a', '3', '\n' and '\0' are all single characters. The difference between 'a' and "a" is that the "a" will be the ascii code for a with the \0 control character appended to the end of it, whereas 'a' will just be the ASCII code for a.

next


 home                      table of contents                      about