DP Computer Science · HL / SL · B2 Programming

B2.3 Programming constructs

Get started
Notes Quiz

What is a Function?

Function: A function is a self-contained block of code designed to perform a specific task. It can accept inputs (called parameters) and produce an output (called a return value).

Functions are one of the most fundamental building blocks in programming. Instead of writing the same code repeatedly, you write it once inside a function and call that function whenever you need it.

A function typically has three key components:

  1. Function Name , a descriptive identifier that reflects its purpose (e.g., calculateArea, getAverage)
  2. Parameters , the inputs the function receives when it is called (there may be zero or more)
  3. Return Value , the output the function sends back to the caller (some functions return nothing)
Exam Tip

Follow the single responsibility principle: each function should do one thing and do it well. This makes functions easier to read, test, and reuse across your programs.

Free preview

8 more sections in this topic

← Previous topicB2.2 Data structuresNext topic →B2.4 Programming algorithms
Koncepts

Learn it properly. Then practise like it's the real paper.

Start free

Features

  • Lessons
  • Past papers
  • Library
  • Homework Help
  • Duels

More

  • For parents
  • Compare
  • Plans & pricing
  • DP for students

Legal

  • Privacy
  • Terms
  • Account deletion

© 2026 Koncepts (product of PrepAiro, Inc). All rights reserved.
DP, IB, EE and TOK are terms of the International Baccalaureate Organization.

Made for IB DP students.