Functions in C Programming

A function is a block of code that performs a specific task. It helps to make programs modular, organized, and reusable.

1. What is a Function?

A function is a self-contained block of statements that performs a particular task. It executes only when it is called.

2. Function Declaration (Prototype)

A function declaration tells the compiler about the function name, return type, and parameters before its actual definition. It ensures that the function is used correctly in the program.

int add(int, int);

3. Function Definition

Function definition contains the actual body of the function where the task is performed.

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

Here: - int → return type - add → function name - a, b → parameters

4. Function Call

A function call is used to execute the function. When a function is called, control transfers to that function.

int result = add(5, 3);

Here: - add(5, 3) is the function call - 5 and 3 are arguments passed to the function

Notes

Function declaration informs the compiler about the function. Function definition contains the actual code. Function call executes the function. Understanding these concepts is essential for modular C programming.