A character constant is a string of printable ASCII characters enclosed in apostrophes. It takes the following form:
'c1c2c3 . . . cn'
Both apostrophes are required.
The value of a character constant is the string of characters between the apostrophes. The value does not include the apostrophes, but does include all spaces or tabs within the apostrophes.
Within a character constant, the apostrophe character is represented
by two consecutive apostrophes with no space or other character
between them (''
).
The length of the character constant is the number of characters
between the apostrophes, except that two consecutive apostrophes
represent a single apostrophe. The length of a character constant
must be in the range of 1 to 2000. Each
character occupies one byte of memory.
If a character constant appears in a numeric context (such as an
expression on the right side of an arithmetic assignment statement),
it is considered a Hollerith constant.
The following examples show valid and invalid character constants:
Valid | |
'WHAT?' | |
'TODAY''S DATE IS:' | |
'The average reply was "12:00"'
| |
Invalid | Explanation |
'HEADINGS | No trailing apostrophe |
''
| Character constant must contain at least one character |