Declarations and Data Types
1. Data Types
Every piece of data must have a type. This tells the computer how much memory to allocate and what operations are possible.
INTEGER: Whole numbers (e.g.,
10, -5).REAL: Numbers with decimals (e.g.,
15.50, -0.5).CHAR: A single character (e.g.,
'A', '$').STRING: Text (e.g.,
"Hello World").BOOLEAN: Logic values (
TRUE or FALSE).2. Variables, Constants, and Assignment
- Variable: A named memory location where the value can change during program execution.
- Constant: A value that remains fixed throughout the program (e.g., PI).
DECLARE StudentName : STRING
DECLARE StudentAge : INTEGER
CONSTANT Discount = 0.10
// Use the assignment arrow ← (not =)
StudentName ← "John Doe"
StudentAge ← 16
DECLARE StudentAge : INTEGER
CONSTANT Discount = 0.10
// Use the assignment arrow ← (not =)
StudentName ← "John Doe"
StudentAge ← 16
3. Arrays (1D and 2D)
Arrays store multiple items of the same data type under one name using an index.
// 1D Array: List of 10 student names
DECLARE Names : ARRAY[1:10] OF STRING
Names[1] ← "Alice"
// 2D Array: Grid (e.g., 3 students, 4 marks each)
DECLARE Marks : ARRAY[1:3, 1:4] OF INTEGER
Marks[1, 1] ← 85
DECLARE Names : ARRAY[1:10] OF STRING
Names[1] ← "Alice"
// 2D Array: Grid (e.g., 3 students, 4 marks each)
DECLARE Marks : ARRAY[1:3, 1:4] OF INTEGER
Marks[1, 1] ← 85
4. Operators
| Type | Operators | Notes |
|---|---|---|
| Arithmetic | + , - , * , / |
Standard math operations. |
| Comparison | = , <> , < , > , <= , >= |
Note: <> means "Not Equal To". |
| Logical | AND , OR , NOT |
Used to combine Boolean conditions. |
| Integer Math | DIV , MOD |
DIV is whole quotient; MOD is remainder. |
5. Library Routines
Common built-in functions you are expected to use in IGCSE pseudocode:
LENGTH(String): Returns the number of characters.SUBSTRING(String, Start, Length): Extracts a part of a string.ROUND(Number, Decimals): Rounds to specified decimal places.UPPER(String)/LOWER(String): Changes text case.
6. Procedures and Functions (Subroutines)
A procedure performs a task. A function performs a task and returns a value.
// Procedure with 2 parameters
PROCEDURE CalculateArea(Length : REAL, Width : REAL)
OUTPUT Length * Width
ENDPROCEDURE
// Function with 2 parameters
FUNCTION FindMax(Num1 : INTEGER, Num2 : INTEGER) RETURNS INTEGER
IF Num1 > Num2 THEN
RETURN Num1
ELSE
RETURN Num2
ENDIF
ENDFUNCTION
PROCEDURE CalculateArea(Length : REAL, Width : REAL)
OUTPUT Length * Width
ENDPROCEDURE
// Function with 2 parameters
FUNCTION FindMax(Num1 : INTEGER, Num2 : INTEGER) RETURNS INTEGER
IF Num1 > Num2 THEN
RETURN Num1
ELSE
RETURN Num2
ENDIF
ENDFUNCTION
⚠️ Exam Note: In pseudocode, always use the Left Arrow
← for assignment. Do not use = for assignment; = is only used for comparing values (e.g., in an IF statement).