Strings can be manipulated using built-in functions. These are commonly tested in Edexcel 4CP0 Paper 1 exams.
| Function | Description | Example | Result |
|---|---|---|---|
| LENGTH(s) | Returns the number of characters in string s | LENGTH("Hello") | 5 |
| SUBSTRING(s, start, len) | Returns len characters from s starting at position start (0-indexed) | SUBSTRING("Computer", 0, 4) | "Comp" |
| UPPER(s) | Converts all characters to upper case | UPPER("hello") | "HELLO" |
| LOWER(s) | Converts all characters to lower case | LOWER("HELLO") | "hello" |
Strings can be joined together using the & operator (not +):
⚠️ Note: SUBSTRING, UPPER, and LOWER are not listed in the Edexcel 4CP0 Appendix 5 pseudocode reference. Only LENGTH and RANDOM appear there. These functions are included here as additional context — exams may not require them, and you will not be penalised for not knowing them.
A local variable is declared inside a procedure or function and only exists while that procedure/function is running. It cannot be accessed from outside the subprogram.
A global variable is declared in the main program and can be accessed from anywhere — including inside procedures and functions. Overusing global variables is considered poor practice as it makes programs harder to debug.
| Feature | Local Variable | Global Variable |
|---|---|---|
| Where declared | Inside a procedure/function | In the main program body |
| Accessible from | Only within that procedure/function | Anywhere in the program |
| Lifetime | Created when subprogram runs; destroyed on exit | Exists for the whole program |
| Risk | Low — cannot accidentally affect other parts | Higher — any part of program can change it |