Functionsinc 200305065757
Functionsinc 200305065757
Library Functions
User-defined Functions
Types of Functions
Types of Functions
double, char, void, short etc. Don’t worry you will understand
these terms better once you go through the examples below.
function_name: It can be anything, however it is advised to
along with the function name, and if the function returns a value,
function body.
the program.
Syntax of function prototype
returnType functionName(type1
argument1, type2
argument2, ...);
Example:
int addNumbers(int a, int b);
Category of Functions
user defined function are further categorized
in four categories.
Function with no return and no argument
Function with no return but arguments
Function with return but no argument
Function with return and arguments
Function with no return no argument
In this method, We won’t pass any arguments to the function
void function_name()
{
// Function body
}
Function with no return no argument
Example
#include<stdio.h>
void Addition(); // Function Declaration
void main()
{
printf("\n ............. \n");
Addition(); // Function Calling
}
void Addition() // Function Definition
{
int Sum, a = 10, b = 20;
Sum = a + b;
printf("\n Sum of a = %d and b = %d is = %d",
a, b, Sum);
}
Function with no return but with arguments
Function with no return but with arguments, does
not return a value but accepts arguments as input.
For this type of function you must define function
// Function body
}
Function with no return but with arguments
#include<stdio.h>
void Addition(int, int);
void main()
{
int a, b;
printf("\n Please Enter two integer values \n");
scanf("%d %d",&a, &b);
Addition(a, b); //Calling the function with dynamic values
}
void Addition(int a, int b)
{
int Sum;
Sum = a + b;
printf("\n Additiontion of %d and %d is = %d \n", a, b, Sum);
}