<aside> <img src="/icons/home_green.svg" alt="/icons/home_green.svg" width="40px" />

Back to Home

</aside>

Example 1: Calculate Sum

Example 2: Tic Tac Toe

Functions and Modular Programming

https://jennychen9827.github.io/CAD281/function.html

Why Use Functions?

function.png

// Example of a simple function
void printWelcome() {
    printf("Welcome to Tic Tac Toe!\\n");
}

Function Components

Each function in the example above has a specific purpose, making the code easier to understand and maintain.

1. Function Declaration (Prototype)

Component Description Example
Return Type What the function returns int, void, float, etc.
Function Name Identifier for the function calculateSum
Parameters Input variables (int a, float b)
// Function Declaration Syntax
returnType functionName(parameterType1, parameterType2);

// Example
int calculateSum(int a, int b);
void displayMessage(char* text);
float getAverage(float numbers[], int size);