- 2070 Asar · 1 mark
How a 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.
Explain how function is defined in C.
A function definition gives the complete function: its header and its body.
General form:
return_type function_name(parameter list)
{
declarations;
statements;
return value;
}
return_type: type of the value returned (voidif 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
{ }; areturnstatement sends the value back to the caller (it may be omitted in avoidfunction).
#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
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Switch versus user defined function · Computer Programming, chapter 5
- Function definition; sum of two numbers · Computer Programming, chapter 6
- Palindrome string using function · Computer Programming, chapter 7
- ZOH and FOH defined; ZOH transfer function · Digital Control System, chapter 1
- Pulse transfer function from a 3×3 state model · Digital Control System, chapter 5