The string handling functions below are used in AQA pseudocode. Characters in a string are indexed from 0.
word ← 'COMPUTER'
a ← LEN(word)
b ← SUBSTRING(2, 4, word)
c ← POSITION(word, 'U')
d ← CHAR_TO_CODE('C')
e ← CODE_TO_CHAR(d + 2)State the value stored in each variable after the code has run. Assume the character set used is ASCII, where 'A' is 65. [5]
- a = 8(1)
- b = 'MPU'(1)
- c = 4(1)
- d = 67(1)
- e = 'E'(1)
- Answer: a 8; b 'MPU'; c 4; d 67; e 'E'
- Examiner tip: SUBSTRING(2, 4, …) includes both positions 2 and 4, so it returns three characters.