This document discusses functions in C programming. It defines built-in functions as pre-defined subprograms in the C language compiler, and user-defined functions as those created by the programmer. Examples are given of programs using built-in functions like scanf(), printf(), and strcpy(), as well as user-defined functions with passing arguments by value and reference. User-defined functions can be default without parameters or parameterized, returning values using the return statement. The document promotes Baabtra Mentoring Partner and provides contact details.
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
Target Achieved & Jobs Applied Tracking
1.
2. Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
5. Function creation &
Function call in c
Muhammed Noufal V T
muhammednoufalvt@gmail.c
om
www.facebook.com/vtnoufa
lvt
twitter.com/noufalurnappy
in.linkedin.com/pub/muham
med-noufal
9744003056
6. Functions in c
• Types of functions
- Built in functions (library
functions)
- User defined functions
• Advantagas
-Decrease the length of the
program
-Easy to manipulate
7. Built in functions
(library functions)
• Sub programs that is already defined in c
language
compiler
• Syntax to call a function
function name();
• Examples :scanf();
printf();
clrscr();
strcpy();
8. Program using Built in
functions (library functions)
•
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[20];
char s2[20];
int l;
clrscr();
printf(“Enter the two stringsn”);
scanf(“%s%s”,s1,s2);
l=strlen(s1);
printf(“length of the string is %d”,&l);
strcat(s1,s2);
printf(“combined string=%s”,s1);
getch();
}
9. User defined functions
• Functions defined by user
• Advantagas
-Reusability
-Easy to manipulate
• Syntax to declare a user defined function
data type function name();
• Syntax to define a user defined function
data type function name()
{
function body;
}
10. Program using user
defined functions
•
#include<stdio.h>
#include<stdio.h>
void main()
{
clrscr();
add();
getch();
}
int add()
{
int a,b,c;
printf(“Enter two numbers to addn”);
scanf(“%d%d”,&a,&b);
c=a+b;
printf(“Addition of the two numbers=%d”,&c)
}
11. user define functions
• Default function
-Function which doesn’t support parameter
variables
• Parameter function
-Function which contains parameter variables
Syntax
data type function name(data type variable
1,… variable n)
• Return statement
-The statement which return values from
functions to calling sections
• Methods of passing argument values to
parameterized function
12. Program using pass by value
method
#include<stdio.h>
#include<conio.h>
int add(int,int);
void main()
{
int a,b,c;
clrscr();
printf(“Enter two numbersn”);
scanf(“%d%d”,&a,&b);
c=add(a,b);
printf(“Addition=%d”,&c);
getch();
}
int add(int n, int m)
{
int s;
s=n+m;
return(s);
}
13. Program using pass by
referanceint add(int *x,int *y)
method
#include<stdio.h>
#include<conio.h>
int add(int *x,int *y)
void main()
{
int a,b,c,*p1,*p2;
clrscr();
printf(“Enter two numbers”);
scanf(“%d%d”,&a,&b);
p1=&a;
p2=&b;
c=add(p1,p2);
printf(“addition=%d”,c);
getch();
}
{
int *z;
*z=*x+*y;
return(*z);
}
14. If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
15. Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550