Skip to content
doubtly

2 answers

Answer: a function is a self-contained, named block of code that performs a specific task. It runs only when it is called, can take inputs (arguments) and can return a value.

Every C program has at least one function, main(). Functions are of two kinds: library functions (like printf(), sqrt()) and user-defined functions.

int add(int a, int b)      /* function definition */
{
    return a + b;
}

int main()
{
    int s = add(5, 3);     /* function call, s = 8 */
    printf("%d", s);
    return 0;
}

A user-defined function has three parts: the declaration (prototype, e.g. int add(int, int);), the definition (the body) and the call.

Advantages: the same code can be reused many times, the program is divided into small manageable modules, and it is easier to read, test and debug.

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.