A user-defined function is a function created by the programmer to perform a specific task. Functions in C help break down complex programs into smaller, manageable parts.

Key Concepts

1. Function Definition and Declaration

A function in C consists of three main parts:

2. Return Type

The return type of a function specifies the type of value the function will return. Common return types include:

Example:

int add(int a, int b); // Function Declaration
int add(int a, int b) { // Function Definition
    return a + b;
}
int main() {
    int sum = add(5, 10); // Function Call
    return 0;
}

3. Parameters and Arguments

Example:

void greet(char name[]) { // Parameter
    printf("Hello, %s!", name);
}
int main() {
    greet("Alice"); // Argument
    return 0;
}