MODULE 3 • LESSON 01
In Module 2 you designed algorithms. In this module you will turn them into working programs in C. Before you write any more C, it helps to step back and ask a bigger question: is there only one way to write a program? The answer is no. Programmers have developed several quite different styles of thinking about code, called programming paradigms. C belongs to one of them; Java, Haskell and SQL belong to others.
In this lesson you will meet the four paradigms in the syllabus: imperative (procedural), object-oriented, functional and declarative. You will see the same kinds of task written in each style, identify the paradigm behind real snippets of code, and sort the key characteristics of each one. You will also see where C fits and why it is the language you are examined in.
What you will learn
- What a programming paradigm is, and how it differs from a programming language.
- The characteristics of the imperative (procedural) paradigm, with C examples.
- The characteristics of the object-oriented paradigm: classes, objects, encapsulation, inheritance and polymorphism.
- The characteristics of the functional paradigm: pure functions, no side effects, recursion and higher-order functions.
- The characteristics of the declarative paradigm, using SQL database queries as the main example.
- How to recognise the paradigm behind a piece of code, and how to compare paradigms in an exam answer.
Part 1: What is a paradigm?
A programming paradigm is a style or approach to programming: a set of ideas about how a program should be organised and how a problem should be broken down. A paradigm is not a language. It is a way of thinking that a language is designed to support.
Think of building a house. You could build it brick by brick, following a list of instructions (imperative). You could build it from prefabricated rooms, each with its own walls, wiring and doors (object-oriented). You could describe it as a set of rules that turn a plot of land into a finished house without changing anything along the way (functional). Or you could hand an architect a description of the house you want and let them work out how to build it (declarative).
Many modern languages are multi-paradigm: Python and C++ let you write procedural or object-oriented code, and JavaScript supports functional ideas too. When we say “Java is object-oriented” we mean that it is designed mainly around that paradigm. Exam answers expect you to name each paradigm, describe its characteristics and give an example language.
| Paradigm | Main idea | Example languages |
| Imperative (procedural) | Tell the computer HOW, step by step; statements change the program’s state | C, Pascal, FORTRAN, COBOL, BASIC |
| Object-oriented | Model the problem as objects that combine data and behaviour | Java, C++, C#, Python, Smalltalk |
| Functional | Build the program from mathematical functions with no changing state | Haskell, Lisp, Erlang, F# |
| Declarative | State WHAT result you want, not how to get it | SQL (database queries), HTML (markup) |
Part 2: The imperative (procedural) paradigm
An imperative program is a sequence of commands that the computer carries out in order. Each command changes the state of the program, which is the current values of its variables. The word comes from the Latin for “to command”. This matches how the processor itself works (Module 1): fetch an instruction, execute it, update registers and memory, then fetch the next one.
The procedural paradigm is imperative programming organised into procedures (called functions in C): named blocks of code that each do one job and are called from a main program. Its key characteristics are:
- Sequence of statements executed in order, from the top of the program down.
- Variables and assignment: values are stored in memory and repeatedly changed (
total = total + mark;). - Control structures: selection (if, switch) and iteration (for, while) control the order of execution, exactly as in Module 2.
- Procedures or functions: the program is decomposed top-down into modules, each called by name, often with parameters and a return value.
- Data and procedures are separate: data is passed to procedures, which act on it.
Worked example 1: a procedural C program
This program follows the top-down design from Module 2. Each procedure does one job, main calls them in sequence, and the loops change the variables i, total and passes as they run.
#include <stdio.h>
/* procedure: works out the average */
float average(int m[], int n)
{
int i, total = 0;
for (i = 0; i < n; i++)
total = total + m[i];
return (float) total / n;
}
/* procedure: counts marks of 50 or more */
int countPasses(int m[], int n)
{
int i, passes = 0;
for (i = 0; i < n; i++)
if (m[i] >= 50)
passes = passes + 1;
return passes;
}
int main(void)
{
int marks[5] = {72, 45, 88, 50, 39};
printf("Average: %.1f\n",
average(marks, 5));
printf("Passes: %d\n",
countPasses(marks, 5));
return 0;
}
Output:
Average: 58.8 Passes: 3
Advantages of procedural programming: it is close to how the computer works, so programs are efficient; it is simple to learn; and the top-down design maps directly onto procedures. Disadvantages: in large programs many procedures may share and change the same data, so a change in one place can break code somewhere else, and the data and the code that uses it can drift apart.
Part 3: The object-oriented paradigm
Object-oriented programming (OOP) organises a program around objects. An object models a real-world thing, such as a bank account, a student or a car, and combines two things: attributes (data about the object) and methods (the actions it can carry out). A class is the blueprint; each object is an instance of a class.
class BankAccount {
private double balance; // attribute
void deposit(double amount) { // method
balance = balance + amount;
}
double getBalance() {
return balance;
}
}
BankAccount mine = new BankAccount();
mine.deposit(250.00);
That is Java. Its key characteristics, which you should be able to name and explain, are:
| Characteristic | Meaning | In the example |
| Classes and objects | A class defines the attributes and methods; objects are created from it | BankAccount is the class; mine is an object |
| Encapsulation | Data and methods are bundled together, and the data is hidden so it can only be changed through the object’s own methods | balance is private; you must call deposit |
| Inheritance | A new class can be based on an existing one, gaining its attributes and methods and adding its own | A SavingsAccount class could extend BankAccount and add interest |
| Polymorphism | The same method call can behave differently depending on the object it is called on | calculateFee() could work differently for a savings and a current account |
| Message passing | Objects work together by calling each other’s methods | mine.deposit(250.00) |
OOP suits large systems built by teams: games, apps with graphical interfaces and business systems. Classes can be reused in other programs, and encapsulation stops one part of the program accidentally damaging another part’s data. The cost is extra complexity and some loss of speed.
Worked example 2: how close can C get?
C is not object-oriented: it has no classes, no methods inside data types, and no inheritance. The nearest you can get is a struct (a record, which you will meet later in this module) plus separate functions that act on it. Compare this with the Java class above: the data and the function are written separately, and nothing stops other code changing the balance directly.
#include <stdio.h>
struct Account {
int number;
float balance;
};
void deposit(struct Account *a, float amt)
{
a->balance = a->balance + amt;
}
int main(void)
{
struct Account acct = {1001, 200.0};
deposit(&acct, 50.0);
printf("Account %d: $%.2f\n",
acct.number, acct.balance);
return 0;
}
Output:
Account 1001: $250.00
Part 4: The functional paradigm
A functional program is built by defining and combining mathematical functions. A function in this sense is like one in maths: give it the same input and it always returns the same output, and it does nothing else. Its key characteristics are:
- Pure functions: the result depends only on the arguments.
- No side effects: a function does not change any variable outside itself, print anything as a hidden extra or alter its input.
- Immutable data: once a value is created it is not changed; instead a new value is produced. There are no assignment statements that update variables.
- Recursion instead of loops: repetition is done by a function calling itself.
- Higher-order functions: functions can be passed to other functions as arguments and returned as results, for example map, filter and reduce.
square x = x * x sumSq = sum (map square [1..10]) fact 0 = 1 fact n = n * fact (n - 1)
This is Haskell. sumSq works out to 385, and fact is defined by recursion: the factorial of n is n times the factorial of n − 1, and the factorial of 0 is 1.
Compare sumSq with the C way: in C you would create a variable total, loop with a counter and keep changing total. In Haskell nothing changes; the result is described as “the sum of the squares of 1 to 10”. Because functions have no side effects, they are easier to test and to run in parallel on many processor cores, which is why functional ideas are used in data processing and telecoms. The disadvantages: the style feels unfamiliar, and programs that must change things all the time (games, devices) are harder to write.
Part 5: The declarative paradigm
In a declarative language you describe what you want, and the language system works out how to get it. You do not write the steps, loops or order of execution yourself. Two important kinds are query languages and logic programming.
The main example: SQL
The declarative language you are most likely to use is SQL (Structured Query Language), the language for working with relational databases. You will use it in Unit 2 when you study databases, and it runs behind almost every school system, online shop and banking app you use.
SELECT name, mark FROM students WHERE mark >= 50 ORDER BY name;
This asks a database for the names and marks of students with 50 or more, in alphabetical order. Read it as a description of the answer: which columns (SELECT), from which table (FROM), which rows (WHERE) and in what order (ORDER BY). You never say how to search the table, whether to use an index, or which sorting method to apply. The database system chooses all of that, and may choose differently tomorrow if the table grows, without your query changing.
Compare the imperative way. In C you would write a loop over every record, an if to test each mark, code to store the matches, and a sorting algorithm to put them in order: perhaps 30 lines that spell out how. The SQL says only what.
SELECT form, AVG(mark) FROM students GROUP BY form;
This second query gives the average mark for each form. Again there is no loop, no running total and no counter. In C you would need all three. SQL statements can also add, change and delete data (INSERT, UPDATE, DELETE), each again stating the result wanted rather than the steps.
Brief aside: logic programming. Another declarative family is logic programming, the best-known language being Prolog. A Prolog program is a set of facts and rules, and the system searches for answers to queries. You only need to recognise the name as a declarative language; SQL is the example to use in your answers.
Declarative languages suit problems where the result is easy to describe but the steps are tedious or best left to the system: above all database queries. They make programs short and close to the problem description, but the programmer has little control over efficiency. Functional programming is often counted as a kind of declarative programming, because it also avoids describing steps that change state. HTML and CSS are declarative too, though they are markup and style languages rather than full programming languages.
Try it 1Paradigm spotter
Read each snippet and choose its paradigm. After you answer, the lines that give it away are highlighted. Use Next and Previous to move through all 12.
Part 6: Comparing the paradigms
| Question | Imperative | Object-oriented | Functional | Declarative |
| Basic building block | Statement, procedure | Object (class) | Function | Query (a description of the result) |
| Does state change? | Yes, constantly | Yes, inside objects | No | Not described by the programmer |
| How is repetition done? | Loops | Loops inside methods | Recursion, map, filter | Handled by the system |
| Programmer describes | How, step by step | Objects and how they interact | What is computed from what | What result is wanted |
| Typical uses | Systems software, embedded devices, utilities | Large apps, games, GUIs, business systems | Data processing, finance, telecoms | Database queries, web page markup, configuration |
Answering exam questions. When asked to "outline" or "describe" a paradigm, give two clear characteristics and a named language. For example: "In the object-oriented paradigm a program is organised as objects created from classes; each object combines attributes and the methods that act on them, and data is protected by encapsulation. Example: Java." When asked to "distinguish" between two paradigms, make each point a direct contrast ("whereas …").
The paradigm that most clearly encourages a modular approach, with the program built from separate procedures designed top-down, is the procedural (imperative) one; this is the approach you will use in C throughout this module. OOP is modular too, but its modules are classes.
Try it 2Sort the characteristics
Each statement describes one paradigm. Choose the paradigm it belongs to. You need all twelve for a full exam-ready set of characteristics.
Part 7: Why C, and why so many paradigms?
CAPE assesses programming in procedural C only. C is a good first serious language because it shows you exactly what the computer is doing: you declare variables and their types, manage memory, and control every step. Once you understand procedural C, learning an object-oriented language such as Java or C++ (which grew out of C) is much easier.
Different paradigms exist because different problems suit different ways of thinking. A database query is clearest in SQL; a game full of characters is clearest as objects; a calculation over millions of records can be split safely across processor cores in a functional style; and a program for a washing machine controller is best as efficient procedural code. Later in this module you will compare how C, C++, Java, JavaScript and Python declare variables and write control structures, and why different languages suit different applications.
Try it 3Paradigm practice
Pick a mode. "Languages" names a language: choose its main paradigm. "Features" names a characteristic: choose the paradigm it belongs to.
Summary
| Idea | Remember |
| Paradigm | A style of programming; a language is designed to support one or more. |
| Imperative / procedural | Statements that change state; control structures; procedures called from main. C, Pascal. |
| Object-oriented | Classes and objects; encapsulation, inheritance, polymorphism. Java, C++. |
| Functional | Pure functions, no side effects, immutable data, recursion, higher-order functions. Haskell, Lisp. |
| Declarative | Say what, not how; the system chooses the steps. SQL queries are the main example. |
Review questions
1. What is a programming paradigm?
Show answer
A style or approach to programming: a way of organising a program and breaking down a problem, which a programming language is designed to support.
2. Outline TWO characteristics of the procedural paradigm.
Show answer
Any two: programs are sequences of statements executed in order; variables are changed by assignment (state changes); control structures (selection, iteration) control the order; the program is broken into procedures/functions called from a main program; data is separate from the procedures that use it.
3. Explain encapsulation and inheritance, using an example.
Show answer
Encapsulation: an object’s data and methods are bundled together and its data is hidden, so it can only be changed through its methods (balance can only change through deposit). Inheritance: a class can be based on another and reuse its attributes and methods (SavingsAccount extends BankAccount and adds interest).
4. Distinguish between the functional and imperative paradigms.
Show answer
In the imperative paradigm the program is a sequence of commands that change variables (state), and repetition uses loops; in the functional paradigm the program is built from pure functions that return values without changing any state, and repetition uses recursion.
5. Why is SQL described as declarative?
Show answer
Because the programmer states what data is wanted (e.g. the names of students with marks of 50 or more) and not how to find it; the database system decides how to search and sort.
6. Which paradigm represents things from the real world as objects that hold data and can carry out actions? Name a language that supports it.
Show answer
The object-oriented paradigm, e.g. Java (or C++, C#, Python).
7. State a benefit and a drawback of object-oriented programming.
Show answer
Advantage (any one): classes can be reused; encapsulation protects data; it models real-world problems naturally; suits large team projects. Disadvantage (any one): more complex to design and learn; programs can be larger and slower.
8. Is C object-oriented? Explain using the struct example from this lesson.
Show answer
No. C has no classes, methods inside types or inheritance. A struct can group data, but the functions that act on it are written separately and nothing hides the data, so there is no encapsulation.
Homework
- Choose a school library. Describe how you would model it in the object-oriented paradigm: name three classes, with two attributes and two methods each. Which class could inherit from another?
- Write the C procedure from Worked example 1 that counts passes as a recursive function instead of a loop. Which paradigm’s idea have you borrowed?
- Write an SQL query that lists the names of products with fewer than 10 in stock, sorted by name. Explain why it is declarative.
- Make a one-page comparison table of the four paradigms, with at least three characteristics and two languages for each. Use it as revision notes.
- Answer the past-paper question on paradigms in the Go further box, then compare your answer with the solution.
Mastery quiz: Programming Paradigms
This 10-question quiz is separate from the short Quick quiz at the end of the lesson. Score 8/10 or higher to earn this lesson’s badge. Your best score is saved in this browser on this device.
Mastery quiz: Programming Paradigms: Imperative, Object-Oriented, Functional and Declarative
Your course badges: loading saved progress…
View badges
No course badges earned yet. Score 8/10 in a lesson quiz to earn its badge.
Saved in this browser on this device. Clearing browser data may remove your badges.
Answer all 10 questions. Earn this lesson’s badge at 8/10 or higher. Read the explanations, revisit the Try it activities and retry as often as you need. These are self-study badges, not formal grades.
Exam tips
Specimen Unit 1 Paper 01 (2021), Items 31 and 33. Recognising a paradigm from a short description. Learn one defining phrase for each: objects with attributes and behaviours (OOP); procedures and modules (procedural); functions without side effects (functional); what not how (declarative).
Specimen Unit 1 Paper 02 (2021), Question 5(a). Outlining two paradigms. For each one give the name, two characteristics and an example language: that is enough for full marks on an "outline" question.
CAPE 2024 Unit 1 Paper 02, Question 6(a). Comparing two paradigms. Write matching points side by side ("objects combine data and methods, whereas a functional program combines functions that do not change data"). A worked answer is linked in the Go further box.
Do not confuse paradigms with generations or levels of language (machine code, assembly, high-level). A paradigm is about style, not about how close the language is to the hardware.
More worked answers are on the CS Solutions page.
Previous: Module 2 • Lesson 10 – Developing Algorithms from Case Problems. Next: Module 3 • Lesson 02 – How Programs Are Translated and Run.
Syllabus link: CAPE Computer Science (CXC A19/U2/21), Programming (Unit 1, Module 3). Specific Objective 1: identify the characteristics of different programming paradigms (procedural or imperative, object-oriented, functional and declarative).
Video search terms
Search YouTube for: "programming paradigms explained", "object oriented vs procedural", "functional programming pure functions", "declarative vs imperative".
Try it 4Quick quiz
Tap an answer. All eight questions are self-checks on this lesson.
Updates
2026/12/01
- Updated the copyright line.
2026/11/24
- First version of the lesson.
© 2026 islandclass.org
