1. Categories of
User Defined Functions in ‘C’
Prakash Khaire
Lecturer, B V Patel Inst. of BMC & IT, Gopal
Vidyanagar
Prakash Khaire, B V Patel Inst. Of BMC &
*
Lecturer IT, Gopal Vidyanagar
2. Introduction
Introduction Functions are categorized based on the arguments are
●
passed or whether a value is returned or not
Category 1
Category 2
●Functions with no agruments and no return values.
●Functions with arguments and no return values.
Category 3 ●Functions with arguments and one return value.
●Functions with no arguments but return a vlues.
Category 4 ●Functions that return multiple values
Category 5
Recursion
*
Prakash Khaire,
Prakash Khaire, Lecturer B V Patel Inst. Of B V Patel Inst. Of BMC & Vidyanagar
BMC & IT, Gopal IT, Gopal Vidyanagar
3. Functions with no arguments and no return values
Introduction
●You do not pass data to the called function.
Category 1 ●function with no return type does not pass
Category 2 back data to the calling function.
●This type of function which does not return
Category 3
any value cannot be used in an expression
Category 4
it can be used only as independent
Category 5 statement.
Recursion
*
Prakash Khaire,
Prakash Khaire, Lecturer B V Patel Inst. Of B V Patel Inst. Of BMC & Vidyanagar
BMC & IT, Gopal IT, Gopal Vidyanagar
4. Functions with no arguments and no return values
Introduction #include<stdio.h>
#include<conio.h> void main()
Category 1 void printline() {
{ clrscr();
Category 2 int i; printf("Welcome to function in C");
printf("n"); printline();
for(i=0;i<30;i++) printf("Function easy to learn.");
Category 3 {
printline();
printf("-");
Category 4 } getch();
printf("n"); }
Category 5 }
Recursion
*
Prakash Khaire,
Prakash Khaire, Lecturer B V Patel Inst. Of B V Patel Inst. Of BMC & Vidyanagar
BMC & IT, Gopal IT, Gopal Vidyanagar
5. Functions with no arguments and no return values
Introduction
Category 1
Category 2
Category 3
Category 4
Category 5
Recursion
*
Prakash Khaire,
Prakash Khaire, Lecturer B V Patel Inst. Of B V Patel Inst. Of BMC & Vidyanagar
BMC & IT, Gopal IT, Gopal Vidyanagar
6. Functions with arguments and no return value
Introduction
●It accept data from calling function.
Category 1 ●you send data to the called function from
Category 2 calling function but you cannot send result
Category 3
data back to the calling function.
Category 4
Category 5
Recursion
*
Prakash Khaire,
Prakash Khaire, Lecturer B V Patel Inst. Of B V Patel Inst. Of BMC & Vidyanagar
BMC & IT, Gopal IT, Gopal Vidyanagar
7. Functions with arguments and no return value
Introduction #include<stdio.h> void main()
#include<conio.h> {
Category 1 void add(int x, int y) clrscr();
{ add(30,15);
Category 2 int result; add(63,49);
result = x+y; add(952,321);
printf("Sum of %d and %d is %d.nn",x,y, getch();
Category 3 result); }
}
Category 4
Category 5
Recursion
*
Prakash Khaire,
Prakash Khaire, Lecturer B V Patel Inst. Of B V Patel Inst. Of BMC & Vidyanagar
BMC & IT, Gopal IT, Gopal Vidyanagar
8. Functions with arguments and no return value
Introduction
Category 1
Category 2
Category 3
Category 4
Category 5
Recursion
*
Prakash Khaire,
Prakash Khaire, Lecturer B V Patel Inst. Of B V Patel Inst. Of BMC & Vidyanagar
BMC & IT, Gopal IT, Gopal Vidyanagar
9. Functions with arguments and return value
Introduction ●It can send arguments (data) from the calling function to the
called function
Category 1
●It wait for the result to be returned back from the called function
Category 2
back to the calling function
●This type of function is mostly used in programming world
Category 3 because it can do two way communications
●It can accept data as arguments as well as can send back data
Category 4 as return value
●The data returned by the function can be used later in our
Category 5 program for further calculations.
Recursion
*
Prakash Khaire,
Prakash Khaire, Lecturer B V Patel Inst. Of B V Patel Inst. Of BMC & Vidyanagar
BMC & IT, Gopal IT, Gopal Vidyanagar
10. Functions with arguments and return value
Introduction #include<stdio.h> void main()
#include<conio.h> {
Category 1
int add(int x, int y) int z;
Category 2
{ clrscr();
int result; z = add(952,321);
Category 3 result = x+y; printf("Result %d.nn",add(30,55));
return(result); printf("Result %d.nn",z);
Category 4 } getch();
}
Category 5
Recursion
*
Prakash Khaire,
Prakash Khaire, Lecturer B V Patel Inst. Of B V Patel Inst. Of BMC & Vidyanagar
BMC & IT, Gopal IT, Gopal Vidyanagar
11. Functions with arguments and return value
Introduction
Category 1
Category 2
Category 3
Category 4
Category 5
Recursion
*
Prakash Khaire,
Prakash Khaire, Lecturer B V Patel Inst. Of B V Patel Inst. Of BMC & Vidyanagar
BMC & IT, Gopal IT, Gopal Vidyanagar
12. Functions with no arguments but returns value
Introduction
●A function which does not take any
Category 1 argument but only returns values to the
Category 2 calling function.
●The best example of this type of function is
Category 3
“getchar()” library function which is declared
Category 4
in the header file “stdio.h”.
Category 5
Recursion
*
Prakash Khaire,
Prakash Khaire, Lecturer B V Patel Inst. Of B V Patel Inst. Of BMC & Vidyanagar
BMC & IT, Gopal IT, Gopal Vidyanagar
13. Functions with no arguments but returns value
Introduction #include<stdio.h>
void main()
#include<conio.h>
Category 1 {
int send()
int z;
{
Category 2 clrscr();
int no1;
z = send();
Category 3 printf("Enter a no : ");
printf("nYou entered : %d.", z);
scanf("%d",&no1);
getch();
Category 4 return(no1);
}
}
Category 5
Recursion
*
Prakash Khaire,
Prakash Khaire, Lecturer B V Patel Inst. Of B V Patel Inst. Of BMC & Vidyanagar
BMC & IT, Gopal IT, Gopal Vidyanagar
14. Functions with no arguments but returns value
Introduction
Category 1
Category 2
Category 3
Category 4
Category 5
Recursion
*
Prakash Khaire,
Prakash Khaire, Lecturer B V Patel Inst. Of B V Patel Inst. Of BMC & Vidyanagar
BMC & IT, Gopal IT, Gopal Vidyanagar
15. Functions that return multiple values
Introduction
●To send values to the called function, in the
Category 1 same way we can also use arguments to
Category 2 send back information to the calling function
●The arguments that are used to send back
Category 3
data are called Output Parameters.
Category 4
Category 5
Recursion
*
Prakash Khaire,
Prakash Khaire, Lecturer B V Patel Inst. Of B V Patel Inst. Of BMC & Vidyanagar
BMC & IT, Gopal IT, Gopal Vidyanagar
16. Functions that return multiple values
Introduction #include<stdio.h>
void main()
#include<conio.h>
Category 1 {
void calc(int x, int y, int
int a=20, b=11, p,q;
*add, int *sub)
Category 2 clrscr();
{
calc(a,b,&p,&q);
Category 3 *add = x+y;
printf("Sum = %d, Sub = %d",p,q);
*sub = x-y;
getch();
Category 4 }
}
Category 5
Recursion
*
Prakash Khaire,
Prakash Khaire, Lecturer B V Patel Inst. Of B V Patel Inst. Of BMC & Vidyanagar
BMC & IT, Gopal IT, Gopal Vidyanagar
17. Recursion
Introduction
●A function calling itself again and again to
Category 1
compute a value
Category 2 ●Normally function are called by main
Category 3 function or by some another function
●But in recursion the same function is called
Category 4
by itself repeatedly
Category 5
Recursion
*
Prakash Khaire,
Prakash Khaire, Lecturer B V Patel Inst. Of B V Patel Inst. Of BMC & Vidyanagar
BMC & IT, Gopal IT, Gopal Vidyanagar
19. Use of Recursive Function
Introduction
●Recursive functions are written with less
Category 1
number of statements compared functions
Category 2 ●Recursion is effective where terms are
Category 3 generated successively to compute a value
Category 4
Category 5
Recursion
*
Prakash Khaire,
Prakash Khaire, Lecturer B V Patel Inst. Of B V Patel Inst. Of BMC & Vidyanagar
BMC & IT, Gopal IT, Gopal Vidyanagar