C Academy · Lesson

Defining and Calling Functions

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

Lesson 1 of 310 steps

Defining and Calling Functions is a free C Academy lesson on CoddyKit. This is 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, and your progress syncs across the web and the CoddyKit app. The C Academy course includes 3 lessons in total.

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

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 }

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;
}

Function Parameters

Functions can accept input values, called parameters.

Example:

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

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;
}

Return Values in Functions

Functions can return values using the return statement.

Example:

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

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;
}

Why Use Functions?

Functions help in:

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

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
Free to start

Learn C with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
39
Lessons
144

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. 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. The C Academy course includes 3 lessons in total.

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, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 3.

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