Skip to main content
1 of 4
Kai Burghardt
  • 1.1k
  • 1
  • 6
  • 13

use string as an array[1‥n] of 0‥ord(maxChar)

In Pascal string literals may contain arbitrary values from the domain of char. Even chr(0) is permitted. The only illegal component is the value denoting a newline (in ASCII chr(10) [“line feed”] and/or chr(13) [“carriage return”]). In other words, multi-line string literals are not allowed. Furthermore the string delimiting character ' (ASCII chr(39)) needs to be escaped (conventionally ''). Example:

program stringArrayDemo(output);
begin
    writeLn(ord(('€Bÿ')[3]))
end.

Since it’s not properly displayed, the above string literal consists of the following characters (ordinal value in hexadecimal base):

80 42 FF 12

Therefore the above program will print 255 as it’s the third character’s ordinal value. Since the maxChar value introduced in ISO standard 10206 “Extended Pascal” documents an implementation characteristic, it is imperative that your solution mentions the processor used. The above program will work adequately if compiled with the GNU Pascal Compiler (GPC) or the Free Pascal Compiler (FPC).

Kai Burghardt
  • 1.1k
  • 1
  • 6
  • 13