Programmers use many different types of data, including but not limited to: integers (whole numbers), floating point numbers, characters, and strings of characters. Each type of data involves its own language in which the "values" (separate items of data within the data type) are each given a unique pattern of on/off switch settings (also known as "binary codes"). Many types of data are defined in the computer simply as a list of binary codes, with each representing one value in that data type. Imagine that we wanted a new data type called "season" to represent the seasons of the year. This would be a very small data set. We could define such a data set in the computer as the list of values: spring, summer, fall, and winter. The C++ programming language provides us with the ability to "enumerate" (list in order) the values in a new data type of our own design with the following statement:
enum season {spring, summer, fall, winter};
The enum (enumeratio) statement above defines an "ordinal" data type. The word ordinal is defined as: "of or pertaining to order, rank, or position in a series". The C++ statement above defines a new data type named season with ordered values, the first being "spring" and the last being "winter". The order in which the values are listed in the enum statement is important. A compiler will see the value spring as being "less than" the value summer when sorting values of this data type.
Be aware that the value spring would not be interpreted as a string (series) of character data here, but rather as a completely new type of data called season data.
Remember that data is defined in the computer as a list of binary codes. In the enum statement above, the code given to the value spring would be 00000000 (equivalent to the value "zero" if we read it as a binary number). The code given to the value summer would be 00000001 (equivalent to the value "one" when read as a binary number). The code given to the value fall would be 00000010 (equivalent to the value "two" when read as a binary number). Etc.
Each binary code (such as the pattern 0000011 used to represent the season winter) also could be read as a binary number (in this case, "three"). This means that every season can be said to have a numeric value. The binary patterns used to represent each season have been selected specifically to allow us to sort them in a reasonable order. The pattern used to represent the season spring has the binary value zero which is less than the one used for the season summer. In this way, any season used by the computer can be sorted in order with other seasons.
The words "predecessor" and "successor" are used to indicate values within an enumerated list that are immediately ahead of (less than) or following (greater than) another value in the list. For example, within the season data type enumerated above, the predecessor to the value summer would be spring; and the successor to summer would be fall. As another example, within the integer data type, the predecessor to the value 5 is 4; and the successor to 5 is 6.
Similar to the season data type in the example above, all of the integer data types in C++ were defined as ordinal data (as a list of values in an order). As you might imagine, the list is much larger than the four values defined for the season data type. On some computers, the data type known as "unsigned int" contains 65536 values (0 to 65535), listed in an obvious increasing order. The data type known simply as "int" (which can store negative or positive sign) also contains 65536 values, but they are the values -32768 to +32767. Standards have changed somewhat over the years as computer processors have improved to allow for larger and larger units of data. For modern standards see the page entitled Data Types in the C++ Programming Language.
Note that floating point data types are not ordinal. This is because, unlike integers, they were not defined as a list of ordered values. Floating point data is not "discrete" (separate individual values). Rather, it is "continuous" (an infinite quantity of values). For any two floating point numbers, there is always a value between them. For example, the numbers 2.7 and 2.8 have the value 2.75 between them. The numbers 2.75 and 2.76 have the value 2.755 between them. And so on. Integer data is discrete (made up of a limited number of separate items). There are no integers between the integers 5 and 6. Any set of integers is "finite" (limited). Floating point data is not finite; it is infinite. Therefore, integers are ordinal data, but floating point numbers are not.
The data type known in C++ as "char" (character data) was also defined as ordinal data. Like the early "short int" data type standard, the list of character values contains 256 binary codes, also defined as an ordered list. For example, the binary code used to represent the character "A" has the binary value 65, which is less than the one used for the character "B" (66). In this way, any character used by the computer can be sorted in order with other characters. This includes all types of characters, including letters, numerals, punctuation, control codes (such as tab or carriage return) and the "extended characters" (not normally seen on a keyboard but available in the computer, such as the copyright symbol "©".
A few different languages (sets of defined coding patterns) have been developed to represent character data, but the most widely used is one called ASCII (the American Standard Code for Information Interchange). In that language, there were originally 128 characters, defined using 7-bit patterns. However that was later improved to use 8-bit patterns to allow for 256 binary codes so that the extended characters could also be coded. The exact order of the characters as they were enumerated can be found in a multitude of published tables, such as the one at:
[http://www.neurophys.wisc.edu/www/comp/docs/ascii.html]
If you refer to that web page, you will see a list of characters (described in the last column), preceded by numeric values that define their positions within the ordered list. The first 32 characters in the ASCII table are control codes rather than visible symbols. These are characters that control the functioning of output devices such as screens or printers to affect the layout of text, but do not normally appear as visible symbols. The "tab" character is a good example of this. The next 32 characters in the ordered table are either frequently used "special characters" (such as standard punctuation) or numerals (digit symbols such as "5"). They are followed by the uppercase characters, then the lowercase characters. This order creates a situation that surprises many novice programmers. Due to the order in which the symbols in the ASCII language were enumerated, the letter "Z" (capital) is interpreted as being "less than" the letter "a" (lowercase). In other words, when sorting character data, the letter uppercase "Z" would be placed ahead of lowercase "a". In the C++ language, the following relational expression would be evaluated as true:
'Z' < 'a'
C++ coding note: Remember that the C++ language requires programmers to identify individual character constants by enclosing them in apostrophes (') rather than the quote marks (") used to enclose strings (groups of characters).
Similarly, because of the order of enumeration in the ASCII data type, the following expressions would also be evaluated as true:
'!' < '2', '2' < 'A', and ' ' < '!'
The last example shows a blank space between the left set of apostrophes. Be clear about the meaning of the positional numbers listed ahead of each character in the table referenced by the link above. They are represented in many different numbering systems (bases) to assist programmers who work in many different bases. Most novices just stick with the first column showing the decimal (base ten) values. These values represent the positions of the characters within the enumerated ASCII data type. For example, the control code character "horizontal tab" has a decimal code value of 9, meaning that it is at position 9 in the table. The character "A" is often referred to a character 65 because of its position. But that does not mean to imply that the character "A" has an actual numeric value. In general (in the computer industry) none of the ASCII characters are actually meant to imply a numeric value. For example, the numeral (symbol) "2" is not intended to represent the value two. In fact, in the ASCII language, the position of the numeral "2" in the enumerated list is 50, not 2. A relational expression of '2' < '3' is true because the (#50) position of the numeral '2' in the table is lower than the (#51) position of the numeral '3', but not because the numerals are seen by the computer as having any numeric value. In the character data type, the character '2' has no more numeric value than the letter 'A' or the punctuation '!'. The C++ programming language blurs this concept a bit because, unlike almost all other languages, C++ allows programmers to treat characters as if they were numerically equivalent to their position in the ASCII table. The flexibility offered by C++ in allowing us to casually switch between the symbol meaning and ordinal position of the character provides us with extremely flexible control over character data. For example, if we wanted to replace the value in a character variable named CH with its successor (the next character in the ACSII table), we could do so with the statement:
CH = CH + 1;
In fact, the C++ language offers us some special operators written specifically to manipulate ordinal data such as the operators "++" (increment a value to its successor) and "--" (decrement a value to its predecessor). The C++ statement above could be written more simply using the ++ operator as in:
++C;
An ordered list of data items (in this case characters), is often referred to as a "collating sequence". Although some programmers memorize the entire ACSII collating sequence, most do not, relying instead on their access to the many published tables available. It is a good idea for novice programmers to remember at least the following order from lowest to highest: control codes, blank space, punctuation and numerals, uppercase letters, then lowercase letters. The table referenced above does not show them, but there is a list of 128 "extended characters" that follow all of the standard characters mentioned so far. They can be seen in the extended table shown at:
[http://www.asciitable.com/]
The extended symbols can be produced using the numeric keypad on most keyboards in combination with the "Alt" key. For example, if you wanted to produce the inverted question mark symbol "¿", you would note that its decimal number position in the Extended ASCII table is 168. So you would hold down the Alt key and (while holding it down) press the digits for the number 168 on the numeric keypad and then release the Alt key. Note that this must be done using the digits on the numeric keypad area of the keyboard. The digits on the top row of keys will not do this.