Function (Programming)

Also known as: procedure, subroutine, method

structure

A named, reusable block of code that performs a specific task, taking input and optionally returning output. Functions enable code reuse, logical organization, and abstraction—the core of all software design.

💡 Intuition

A mini-program with a name. Call it by name whenever you need that task done.

Core Idea

Write once, use many times. Functions take input (parameters) and give output (return value).

🔬 Example

calculateArea(width, height) → returns width \times height. Use it anywhere, any time.

🎯 Why It Matters

Functions enable code reuse, logical organization, and abstraction—the core of all software design.

⚠️ Common Confusion

Defining a function doesn't run it—you must call the function.

Related Concepts

How Function (Programming) Connects to Other Ideas

To understand function (programming), you should first be comfortable with algorithm and abstraction. Once you have a solid grasp of function (programming), you can move on to parameters, return values and scope.

Go Deeper

Frequently Asked Questions

What is Function (Programming) in CS Thinking?

A named, reusable block of code that performs a specific task, taking input and optionally returning output.

Why is Function (Programming) important?

Functions enable code reuse, logical organization, and abstraction—the core of all software design.

What do students usually get wrong about Function (Programming)?

Defining a function doesn't run it—you must call the function.

What should I learn before Function (Programming)?

Before studying Function (Programming), you should understand: algorithm, abstraction.

💻 Animated Visualization Animated

Call the same function with different inputs