A function is a set of statements used to perform various tasks. In C programming, at least one function must be present. Functions are particularly helpful when you have too many lines of code; you can create a function for a specific task.
Some functions are user-defined, which you can create and use, while others are system-defined (e.g., main(), strrev(), strcat()).
A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function problem. A function is also known as a module.
Functions support modular programming, an approach to solving complex problems.
Moduler Programming is a strategy applied to the design and development of the software system.It is design and development of the software system.It is defined as organizing a large program into small.independent rogram segment called modules.It is basically a 'divide and conquer' approach to problem solving.
In C Programming ,A Function is Standard Library Function if it is system define and we can able to use without any code only use function name.
Examplescanf(),printf(),strrev(),strcat() etc.
A user defined function is a programmed routine that has its parameters set by the user of the system. User defined functions often are seen as programming shortcuts as they define functions that perform specific tasks within a larger system.
Example/* User defined function for addition */ void add(int a, int b) { return a + b; }void add(int a,int b);
It is a simple function prototype also function declaration.
In a programming an identifier must be declear first before using in the program,in the same way, A function prototype must be decleared frist before using(calling) in the program.
return_type function_name(formal arguments or actual arguments) { local declarations or global declarations; return statement; }Example
#include<stdio.h> int sum(int x, int y); int sum(int x, int y) { int z; z = x + y; return z; } int main() { int x, y, add; printf("Enter the first value="); scanf("%d", &x); printf("Enter the second value="); scanf("%d", &y); add = sum(x, y); printf("%d", add); return 0; }
Here,
function Name=sum.
return type=int.
parameters: x and y.