Functions
C Functions
C function is a self contained block of statements that can be executed repeatedly whenever we need it.
Benefits of using function in C
There are two types of functions in C
Parts of Function
1. Function Prototype
Syntax:
dataType functionName (Parameter List)
Example:
int addition();
2. Function Definition
Syntax:
returnType functionName(Function arguments){
//body of the function
}
Example:
int addition()
{
}
3. Calling a function in C
Program to illustrate Addition of Two Numbers using User Defined Function
Example:
#include<stdio.h>
/* function declaration */
int addition();
int main()
{
/* local variable definition */
int answer;
/* calling a function to get addition value */
answer = addition();
printf("The addition of two numbers is: %d\n",answer);
return 0;
}
/* function returning the addition of two numbers */
int addition()
{
/* local variable definition */
int num1 = 10, num2 = 5;
return num1+num2;
}
Program Output:
The addition of two numbers is: 15
Comments
Post a Comment