Introduction
This question tested the following topics/items:
- Programming paradigms: object-oriented vs. functional
- Stages of the program translation process: lexical analysis, syntax analysis, code generation
- The need for different programming languages
- Writing a C function that processes an array
Part a)
An object-oriented language organises a program around objects, which combine data (attributes) and the methods that operate on that data. Objects are created from classes and use features such as encapsulation and inheritance, e.g. Java, C++.
A functional language builds a program by applying and combining mathematical functions. Functions return values without changing the program’s state (no side effects), and data is usually not modified once created, e.g. Haskell, Lisp.
See this note: External Resource: Types of Programming languages
Part b) i)
Lexical analysis: The source code is broken up into tokens (keywords, identifiers, operators, literals, punctuation). White space and comments are removed, a symbol table is built, and illegal tokens (lexical errors) are reported.
Part b) ii)
Syntax analysis: The tokens are checked against the grammatical rules of the language, and a parse tree is generated. Syntax errors (e.g. a missing semicolon or bracket) are reported.
Part b) iii)
Code generation: The (optimised) intermediate code is converted into the target machine’s assembly/object code (machine instructions), and memory locations and registers are assigned to the variables.
See this note: Translation (Program Translation During the Compilation process), Lexical Analysis, Syntax analysis (parsing), Code Generation (Object Code)
Part c)
Different programming languages are needed because each is designed to suit a particular type of application, so no single language is the best choice for every problem:
- JavaScript is designed for web applications. It runs inside the web browser and can make web pages interactive (e.g. validating a form or updating page content) without needing to reload the page.
- C/C++ is used for games (and system software) because it compiles to fast machine code and gives the programmer low-level control over memory and hardware, which is needed for high-performance graphics.
- Other examples: FORTRAN for formula translation (scientific and mathematical calculations), and Swift/Kotlin for mobile device applications.
Therefore, the language is chosen based on how appropriate it is for the application (speed, platform, ease of development and the features it provides).
See this note: External Resource: Types of Programming languages
Part d)
void maximum(int arr[], int size)
{
int i;
int max = arr[0]; //assume the first element is the largest
for (i = 1; i < size; i++) //compare against every other element
{
if (arr[i] > max)
max = arr[i]; //a larger value was found
}
printf("The maximum value is %d\n", max);
}
Further explanation
The function returns void since it should not return a value. It starts by assuming that arr[0] is the largest, and then traverses the rest of the array using a loop. Whenever a larger element is found, it replaces max. After the loop, max holds the largest value, which is printed.
A complete program to test the function (writing the function only would be sufficient):
#include <stdio.h>
//prints the largest value stored in arr; size is the number of elements
void maximum(int arr[], int size)
{
int i;
int max = arr[0]; //assume the first element is the largest
for (i = 1; i < size; i++) //compare against every other element
{
if (arr[i] > max)
max = arr[i]; //a larger value was found
}
printf("The maximum value is %d\n", max);
}
int main()
{
int numbers[] = {12, 45, -3, 67, 9};
maximum(numbers, 5); //prints: The maximum value is 67
return 0;
}
See this note: Introduction to functions, Linear search
Links to Notes
© 2026 Vedesh Kungebeharry. All rights reserved.

