0Pricing
C Academy · Lesson

Defining and Calling Functions

Write functions with parameters and return values, and understand the importance of modular programming

Defining and Calling Functions is a free C Academy lesson on CoddyKit — lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

1

Defining and Calling Functions

Functions allow us to break a program into smaller, reusable parts.

In this lesson, you will learn how to:

  • Define and call functions.
  • Use function parameters and return values.
  • Write modular and efficient code.
Defining and Calling Functions — illustration 1

2

What is a Function?

A function is a block of code that performs a specific task.

Functions improve code readability, reusability, and organization.

Example syntax:

returnType functionName(parameters) { // Function body }

3

Example: Defining and Calling a Function

This program defines a function that prints a message.

#include <stdio.h>

void greet() {
    printf("Hello from a function!\n");
}

int main() {
    greet();
    return 0;
}

4

Function Parameters

Functions can accept input values, called parameters.

Example:

void greetUser(char name[]) { printf("Hello, %s!\n", name); }

5

Example: Function with Parameters

This program defines a function that greets a user by name.

#include <stdio.h>

void greetUser(char name[]) {
    printf("Hello, %s!\n", name);
}

int main() {
    greetUser("Alice");
    return 0;
}

6

Return Values in Functions

Functions can return values using the return statement.

Example:

int add(int a, int b) { return a + b; }

7

Example: Function with Return Value

This program adds two numbers and returns the result.

#include <stdio.h>

int add(int a, int b) {
    return a + b;
}

int main() {
    int result = add(5, 10);
    printf("Sum: %d\n", result);
    return 0;
}

8

9

Why Use Functions?

Functions help in:

  • Reducing code duplication.
  • Improving readability and maintainability.
  • Organizing complex programs into smaller parts.

10

Summary

In this lesson, you learned:

  • How to define and call functions.
  • How to pass parameters to functions.
  • How to return values from functions.

Next, we will learn about function prototypes and variable scope in C!

Defining and Calling Functions — illustration 10

Frequently asked questions

Is the “Defining and Calling Functions” lesson free?

Yes — the full text of “Defining and Calling Functions” is free to read here on the web, and the C Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C Academy course, upgrade to CoddyKit PRO.

What will I learn in “Defining and Calling Functions”?

Write functions with parameters and return values, and understand the importance of modular programming You practise C Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start C Academy?

No prior experience is required. C Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 3, so you can start here or from the beginning and move at your own pace.

How long does the “Defining and Calling Functions” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this C Academy lesson?

Yes. Every C Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Defining and Calling Functions
  2. Function Prototypes and Scope
  3. Recursion in C
← Back to C Academy