---
title: "How a function is defined in C"
subject: "Computer Programming"
chapter: 6
key: "semester_1/computer_programming:function-definition-in-c"
source: https://www.bctengineer.com/q/semester_1/computer_programming/function-definition-in-c
site: BCT Engineering
---

# How a function is defined in C

Computer Programming · Chapter 6: User-Defined Functions

- Asked in: 2070 Asar, 1 marks
- Video: [Function Definition in C](https://www.youtube.com/watch?v=gF7wjwM9Jjs) — Neso Academy
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/function-definition-in-c
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-6

## Question

Explain how function is defined in C.

## Short answer

A function definition includes a return type, name, parameter list in parentheses, and a body in braces containing declarations and statements. For example, int maxof(int a, int b) { return (a > b) ? a : b; } defines a function that returns the larger of two integers.

## Answer

A **function definition** gives the complete function: its header and its body.

**General form:**
```text
return_type function_name(parameter list)
{
    declarations;
    statements;
    return value;
}
```
- `return_type`: type of the value returned (`void` if nothing).
- `function_name`: an identifier chosen by the programmer.
- parameter list: the type and name of each formal parameter, separated by commas.
- body: the declarations and statements within `{ }`; a `return` statement sends the value back to the caller (it may be omitted in a `void` function).

```c
#include <stdio.h>
int maxof(int a, int b)       /* return type, name, parameter list */
{                             /* body starts */
    if (a > b)
        return a;
    return b;
}                             /* body ends */
int main(void)
{
    printf("%d\n", maxof(14, 9));
    return 0;
}
```
Output: `14`

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Function definition has?
   A. Header and body
   B. Only header
   C. Only body
   D. Only name
   Answer: A. Complete. (Key point: Definition)

2. void return type means?
   A. Returns 0
   B. Nothing returned
   C. Int
   D. Error
   Answer: B. void. (Key point: Return)

3. Parameter list contains?
   A. Values
   B. Types only
   C. Type and name of each formal parameter
   D. Names only
   Answer: C. Formal params. (Key point: Header)

## Related in Computer Programming

- [Switch versus user defined function](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aswitch-vs-user-function) — Computer Programming, chapter 5
- [Function definition; sum of two numbers](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afunction-definition-sum-two) — Computer Programming, chapter 6
- [Palindrome string using function](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apalindrome-string-function) — Computer Programming, chapter 7

## Related in other subjects

- [ZOH and FOH defined; ZOH transfer function](https://www.bctengineer.com/question.md?key=semester_6%2Fdigital_control_system%3Azoh-foh-definition) — Digital Control System, chapter 1
- [Pulse transfer function from a 3×3 state model](https://www.bctengineer.com/question.md?key=semester_6%2Fdigital_control_system%3Apulse-tf-third-order-numeric) — Digital Control System, chapter 5
