Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
User-defined Functions
Topics
 Function and it’s advantages
 Form of C Function
 Calling function
Function and it’s advantages
 Function: A set of statement(s) to solve
certain kind of problem is called function.
Each function has it’s own name. Ex:
printf(), scanf(), sqrt() etc.
 Advantages of Function in C:
1. The length of source program can be
reduced.
2. It is easy to locate and isolate a faulty
function.
3. A function may be used by many other
function.
Classification of Function
 Functions can be classified into two
categories.
1. Built in function: The function which is
build in the C is called built in function. Ex:
printf(), scanf(), getch().
2. User defined function: The functions
which are designed by programmer called
user defined function.
Form of C Function
 The form of function:
return_type function_name(argument list)
{
local variable declarations;
statement(s);
return(expression);
}
 Here argument list contains valid variable names
separated by commas. Return_type is the type of
the data returned from function.
Continue…
 Example of function:
int add(int a, int b)
{
int sum;
sum= a+b;
return(sum);
}
Calling of Function
 We can call C function by mentioning the
name with appropriate argument.
 Example of calling:
main()
{
int x=10, y=20,z;
z = add(x,y);
printf(“Summation = %d”,z);
}
Call by Value
 In this case of function calling, the value of actual
parameter is passed to the formal parameter. Here
constant value or variable can be used as actual
parameter. If we change the value of formal parameter then
there is no effect in actual parameter.
 void change(int x)
{
x = x + 10;
}
main()
{ int k = 10;
change(k);
printf(“%d”,k);
}
Call by Reference
 Here the address of actual parameter is passed to the
formal parameter. We cannot use address directly. If we
change the value of formal parameter then the value of
actual parameter also changed.
 Void change(int *x)
{
*x = *x+10;
}
main()
{ int k=10;
change(&k);
printf(“%d”,k);
}
Nesting of C Function
 C permits nesting of functions freely. Function1 can call function2,
function2 can call function3,……….and so on.
 main()
{
int a,b,c;
function1();
}
function1()
{
…….
function2();
}
function2()
{
………
}
Recursion
 When a function calls itself is called
recursion. Simple example-
 main()
{
printf(“This is Recursion”);
main();
}
 When executed, the output like
This is Recursion
This is Recursion
This is
Continue..
 A recursive function for factorial:
int factorial(int n)
{
if(n==0)
return(1);
else
return(n*factorial(n-1));
}
Function with Array
 Like the values of simple variables, it is also
possible to pass the values of an array to a
function.
 main()
{
static int value[ ]={10,45,25,40};
printf(“Largest value: %d”,maximum(value,4));
}
int maximum(int x[ ], int n)
{ int i, max=0;
for(i=0;i<n;i++)
if(max<x[i])
max=x[i];
return(max);
}

More Related Content

What's hot

C functions
C functionsC functions
Functions in C++
Functions in C++Functions in C++
Functions in C++
Sachin Sharma
 
Exception handling
Exception handlingException handling
Exception handling
Pranali Chaudhari
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
Functions in C
Functions in CFunctions in C
Functions in C
Shobhit Upadhyay
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
temkin abdlkader
 
Function in C
Function in CFunction in C
Function in C
Dr. Abhineet Anand
 
Function in c program
Function in c programFunction in c program
Function in c program
umesh patil
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
Rokonuzzaman Rony
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
Mohammed Sikander
 
Inline function
Inline functionInline function
Inline function
Tech_MX
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
sai tarlekar
 
Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++
Danial Mirza
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
Jasleen Kaur (Chandigarh University)
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
Vishalini Mugunen
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
Anil Pokhrel
 
C Pointers
C PointersC Pointers
C Pointers
omukhtar
 
POINTERS IN C
POINTERS IN CPOINTERS IN C
POINTERS IN C
Neel Mungra
 

What's hot (20)

C functions
C functionsC functions
C functions
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Exception handling
Exception handlingException handling
Exception handling
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
 
Function in C
Function in CFunction in C
Function in C
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Inline function
Inline functionInline function
Inline function
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
C Pointers
C PointersC Pointers
C Pointers
 
POINTERS IN C
POINTERS IN CPOINTERS IN C
POINTERS IN C
 

Similar to Chap 9(functions)

C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
kavitha muneeshwaran
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdf
BoomBoomers
 
Functions
FunctionsFunctions
Functions
Pragnavi Erva
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
Mehul Desai
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
SangeetaBorde3
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
Hattori Sidek
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
Venkatesh Goud
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
KhurramKhan173
 
unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdf
JAVVAJI VENKATA RAO
 
C functions list
C functions listC functions list
function in in thi pdf you will learn what is fu...
function in  in thi pdf you will learn   what                           is fu...function in  in thi pdf you will learn   what                           is fu...
function in in thi pdf you will learn what is fu...
kushwahashivam413
 
Unit 3 (1)
Unit 3 (1)Unit 3 (1)
Unit 3 (1)
Sowri Rajan
 
Computer-programming-User-defined-function-1.pptx
Computer-programming-User-defined-function-1.pptxComputer-programming-User-defined-function-1.pptx
Computer-programming-User-defined-function-1.pptx
JohnRehldeGracia
 
functions
functionsfunctions
functions
Makwana Bhavesh
 
1.6 Function.pdf
1.6 Function.pdf1.6 Function.pdf
1.6 Function.pdf
NirmalaShinde3
 
functionsamplejfjfjfjfjfhjfjfhjfgjfg_v1.ppt
functionsamplejfjfjfjfjfhjfjfhjfgjfg_v1.pptfunctionsamplejfjfjfjfjfhjfjfhjfgjfg_v1.ppt
functionsamplejfjfjfjfjfhjfjfhjfgjfg_v1.ppt
RoselinLourd
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functions
nikshaikh786
 
function_v1.ppt
function_v1.pptfunction_v1.ppt
function_v1.ppt
ssuser823678
 
function_v1.ppt
function_v1.pptfunction_v1.ppt
function_v1.ppt
ssuser2076d9
 
cp Module4(1)
cp Module4(1)cp Module4(1)
cp Module4(1)
Amarjith C K
 

Similar to Chap 9(functions) (20)

C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdf
 
Functions
FunctionsFunctions
Functions
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdf
 
C functions list
C functions listC functions list
C functions list
 
function in in thi pdf you will learn what is fu...
function in  in thi pdf you will learn   what                           is fu...function in  in thi pdf you will learn   what                           is fu...
function in in thi pdf you will learn what is fu...
 
Unit 3 (1)
Unit 3 (1)Unit 3 (1)
Unit 3 (1)
 
Computer-programming-User-defined-function-1.pptx
Computer-programming-User-defined-function-1.pptxComputer-programming-User-defined-function-1.pptx
Computer-programming-User-defined-function-1.pptx
 
functions
functionsfunctions
functions
 
1.6 Function.pdf
1.6 Function.pdf1.6 Function.pdf
1.6 Function.pdf
 
functionsamplejfjfjfjfjfhjfjfhjfgjfg_v1.ppt
functionsamplejfjfjfjfjfhjfjfhjfgjfg_v1.pptfunctionsamplejfjfjfjfjfhjfjfhjfgjfg_v1.ppt
functionsamplejfjfjfjfjfhjfjfhjfgjfg_v1.ppt
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functions
 
function_v1.ppt
function_v1.pptfunction_v1.ppt
function_v1.ppt
 
function_v1.ppt
function_v1.pptfunction_v1.ppt
function_v1.ppt
 
cp Module4(1)
cp Module4(1)cp Module4(1)
cp Module4(1)
 

More from Bangabandhu Sheikh Mujibur Rahman Science and Technology University

Antenna (2)
Antenna (2)Antenna (2)
Voltage suppler..
Voltage suppler..Voltage suppler..
Number system
Number systemNumber system
Chapter 15
Chapter 15Chapter 15
Chap 13(dynamic memory allocation)
Chap 13(dynamic memory allocation)Chap 13(dynamic memory allocation)
Chap 12(files)
Chap 12(files)Chap 12(files)
Chap 11(pointers)
Chap 11(pointers)Chap 11(pointers)
Chap 10(structure and unions)
Chap 10(structure and unions)Chap 10(structure and unions)
Chap 8(strings)
Chap 8(strings)Chap 8(strings)
Chap 7(array)
Chap 7(array)Chap 7(array)
Chap 6(decision making-looping)
Chap 6(decision making-looping)Chap 6(decision making-looping)
Chap 5(decision making-branching)
Chap 5(decision making-branching)Chap 5(decision making-branching)
Chap 3(operator expression)
Chap 3(operator expression)Chap 3(operator expression)
Chap 2(const var-datatype)
Chap 2(const var-datatype)Chap 2(const var-datatype)
Computer hardware ppt1
Computer hardware ppt1Computer hardware ppt1
# Operating system
# Operating system# Operating system
Magnetism 3
Magnetism 3Magnetism 3
Magnetism 2
Magnetism 2Magnetism 2
2. sinusoidal waves
2. sinusoidal waves2. sinusoidal waves
Magnetism 1
Magnetism 1Magnetism 1

More from Bangabandhu Sheikh Mujibur Rahman Science and Technology University (20)

Antenna (2)
Antenna (2)Antenna (2)
Antenna (2)
 
Voltage suppler..
Voltage suppler..Voltage suppler..
Voltage suppler..
 
Number system
Number systemNumber system
Number system
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
Chap 13(dynamic memory allocation)
Chap 13(dynamic memory allocation)Chap 13(dynamic memory allocation)
Chap 13(dynamic memory allocation)
 
Chap 12(files)
Chap 12(files)Chap 12(files)
Chap 12(files)
 
Chap 11(pointers)
Chap 11(pointers)Chap 11(pointers)
Chap 11(pointers)
 
Chap 10(structure and unions)
Chap 10(structure and unions)Chap 10(structure and unions)
Chap 10(structure and unions)
 
Chap 8(strings)
Chap 8(strings)Chap 8(strings)
Chap 8(strings)
 
Chap 7(array)
Chap 7(array)Chap 7(array)
Chap 7(array)
 
Chap 6(decision making-looping)
Chap 6(decision making-looping)Chap 6(decision making-looping)
Chap 6(decision making-looping)
 
Chap 5(decision making-branching)
Chap 5(decision making-branching)Chap 5(decision making-branching)
Chap 5(decision making-branching)
 
Chap 3(operator expression)
Chap 3(operator expression)Chap 3(operator expression)
Chap 3(operator expression)
 
Chap 2(const var-datatype)
Chap 2(const var-datatype)Chap 2(const var-datatype)
Chap 2(const var-datatype)
 
Computer hardware ppt1
Computer hardware ppt1Computer hardware ppt1
Computer hardware ppt1
 
# Operating system
# Operating system# Operating system
# Operating system
 
Magnetism 3
Magnetism 3Magnetism 3
Magnetism 3
 
Magnetism 2
Magnetism 2Magnetism 2
Magnetism 2
 
2. sinusoidal waves
2. sinusoidal waves2. sinusoidal waves
2. sinusoidal waves
 
Magnetism 1
Magnetism 1Magnetism 1
Magnetism 1
 

Recently uploaded

Lecture Notes Unit4 Chapter13 users , roles and privileges
Lecture Notes Unit4 Chapter13 users , roles and privilegesLecture Notes Unit4 Chapter13 users , roles and privileges
Lecture Notes Unit4 Chapter13 users , roles and privileges
Murugan146644
 
Introduction to Banking System in India.ppt
Introduction to Banking System in India.pptIntroduction to Banking System in India.ppt
Introduction to Banking System in India.ppt
Dr. S. Bulomine Regi
 
MVC Interview Questions PDF By ScholarHat
MVC Interview Questions PDF By ScholarHatMVC Interview Questions PDF By ScholarHat
MVC Interview Questions PDF By ScholarHat
Scholarhat
 
E-learning Odoo 17 New features - Odoo 17 Slides
E-learning Odoo 17  New features - Odoo 17 SlidesE-learning Odoo 17  New features - Odoo 17 Slides
E-learning Odoo 17 New features - Odoo 17 Slides
Celine George
 
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - ...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - ...BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - ...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - ...
Nguyen Thanh Tu Collection
 
MATATAG CURRICULUM sample lesson exemplar.docx
MATATAG CURRICULUM sample lesson exemplar.docxMATATAG CURRICULUM sample lesson exemplar.docx
MATATAG CURRICULUM sample lesson exemplar.docx
yardenmendoza
 
How To Sell Hamster Kombat Coin In Pre-market
How To Sell Hamster Kombat Coin In Pre-marketHow To Sell Hamster Kombat Coin In Pre-market
How To Sell Hamster Kombat Coin In Pre-market
Sikandar Ali
 
The Cruelty of Animal Testing in the Industry.pdf
The Cruelty of Animal Testing in the Industry.pdfThe Cruelty of Animal Testing in the Industry.pdf
The Cruelty of Animal Testing in the Industry.pdf
luzmilaglez334
 
Mail Server Configuration Using App passwords in Odoo 17
Mail Server Configuration Using App passwords in Odoo 17Mail Server Configuration Using App passwords in Odoo 17
Mail Server Configuration Using App passwords in Odoo 17
Celine George
 
FIRST AID PRESENTATION ON INDUSTRIAL SAFETY by dr lal.ppt
FIRST AID PRESENTATION ON INDUSTRIAL SAFETY by dr lal.pptFIRST AID PRESENTATION ON INDUSTRIAL SAFETY by dr lal.ppt
FIRST AID PRESENTATION ON INDUSTRIAL SAFETY by dr lal.ppt
ashutoshklal29
 
Lange and Roberts "DEIA in the Scholarly Landscape Session 5: DEIA in Peer Re...
Lange and Roberts "DEIA in the Scholarly Landscape Session 5: DEIA in Peer Re...Lange and Roberts "DEIA in the Scholarly Landscape Session 5: DEIA in Peer Re...
Lange and Roberts "DEIA in the Scholarly Landscape Session 5: DEIA in Peer Re...
National Information Standards Organization (NISO)
 
Parent PD Design for Professional Development .docx
Parent PD Design for Professional Development .docxParent PD Design for Professional Development .docx
Parent PD Design for Professional Development .docx
AntonioJarligoCompra
 
Introduction to Google Productivity Tools for Office and Personal Use
Introduction to Google Productivity Tools for Office and Personal UseIntroduction to Google Productivity Tools for Office and Personal Use
Introduction to Google Productivity Tools for Office and Personal Use
Excellence Foundation for South Sudan
 
Java MCQ Questions and Answers PDF By ScholarHat
Java MCQ Questions and Answers PDF By ScholarHatJava MCQ Questions and Answers PDF By ScholarHat
Java MCQ Questions and Answers PDF By ScholarHat
Scholarhat
 
2 Post harvest Physiology of Horticulture produce.pptx
2 Post harvest Physiology of Horticulture  produce.pptx2 Post harvest Physiology of Horticulture  produce.pptx
2 Post harvest Physiology of Horticulture produce.pptx
UmeshTimilsina1
 
Open Source and AI - ByWater Closing Keynote Presentation.pdf
Open Source and AI - ByWater Closing Keynote Presentation.pdfOpen Source and AI - ByWater Closing Keynote Presentation.pdf
Open Source and AI - ByWater Closing Keynote Presentation.pdf
Jessica Zairo
 
View Inheritance in Odoo 17 - Odoo 17 Slides
View Inheritance in Odoo 17 - Odoo 17  SlidesView Inheritance in Odoo 17 - Odoo 17  Slides
View Inheritance in Odoo 17 - Odoo 17 Slides
Celine George
 
PRESS RELEASE - UNIVERSITY OF GHANA, JULY 16, 2024.pdf
PRESS RELEASE - UNIVERSITY OF GHANA, JULY 16, 2024.pdfPRESS RELEASE - UNIVERSITY OF GHANA, JULY 16, 2024.pdf
PRESS RELEASE - UNIVERSITY OF GHANA, JULY 16, 2024.pdf
nservice241
 
How to Manage Shipping Connectors & Shipping Methods in Odoo 17
How to Manage Shipping Connectors & Shipping Methods in Odoo 17How to Manage Shipping Connectors & Shipping Methods in Odoo 17
How to Manage Shipping Connectors & Shipping Methods in Odoo 17
Celine George
 
Genetics Teaching Plan: Dr.Kshirsagar R.V.
Genetics Teaching Plan: Dr.Kshirsagar R.V.Genetics Teaching Plan: Dr.Kshirsagar R.V.
Genetics Teaching Plan: Dr.Kshirsagar R.V.
DrRavindrakshirsagar1
 

Recently uploaded (20)

Lecture Notes Unit4 Chapter13 users , roles and privileges
Lecture Notes Unit4 Chapter13 users , roles and privilegesLecture Notes Unit4 Chapter13 users , roles and privileges
Lecture Notes Unit4 Chapter13 users , roles and privileges
 
Introduction to Banking System in India.ppt
Introduction to Banking System in India.pptIntroduction to Banking System in India.ppt
Introduction to Banking System in India.ppt
 
MVC Interview Questions PDF By ScholarHat
MVC Interview Questions PDF By ScholarHatMVC Interview Questions PDF By ScholarHat
MVC Interview Questions PDF By ScholarHat
 
E-learning Odoo 17 New features - Odoo 17 Slides
E-learning Odoo 17  New features - Odoo 17 SlidesE-learning Odoo 17  New features - Odoo 17 Slides
E-learning Odoo 17 New features - Odoo 17 Slides
 
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - ...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - ...BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - ...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH LỚP 12 - GLOBAL SUCCESS - FORM MỚI 2025 - ...
 
MATATAG CURRICULUM sample lesson exemplar.docx
MATATAG CURRICULUM sample lesson exemplar.docxMATATAG CURRICULUM sample lesson exemplar.docx
MATATAG CURRICULUM sample lesson exemplar.docx
 
How To Sell Hamster Kombat Coin In Pre-market
How To Sell Hamster Kombat Coin In Pre-marketHow To Sell Hamster Kombat Coin In Pre-market
How To Sell Hamster Kombat Coin In Pre-market
 
The Cruelty of Animal Testing in the Industry.pdf
The Cruelty of Animal Testing in the Industry.pdfThe Cruelty of Animal Testing in the Industry.pdf
The Cruelty of Animal Testing in the Industry.pdf
 
Mail Server Configuration Using App passwords in Odoo 17
Mail Server Configuration Using App passwords in Odoo 17Mail Server Configuration Using App passwords in Odoo 17
Mail Server Configuration Using App passwords in Odoo 17
 
FIRST AID PRESENTATION ON INDUSTRIAL SAFETY by dr lal.ppt
FIRST AID PRESENTATION ON INDUSTRIAL SAFETY by dr lal.pptFIRST AID PRESENTATION ON INDUSTRIAL SAFETY by dr lal.ppt
FIRST AID PRESENTATION ON INDUSTRIAL SAFETY by dr lal.ppt
 
Lange and Roberts "DEIA in the Scholarly Landscape Session 5: DEIA in Peer Re...
Lange and Roberts "DEIA in the Scholarly Landscape Session 5: DEIA in Peer Re...Lange and Roberts "DEIA in the Scholarly Landscape Session 5: DEIA in Peer Re...
Lange and Roberts "DEIA in the Scholarly Landscape Session 5: DEIA in Peer Re...
 
Parent PD Design for Professional Development .docx
Parent PD Design for Professional Development .docxParent PD Design for Professional Development .docx
Parent PD Design for Professional Development .docx
 
Introduction to Google Productivity Tools for Office and Personal Use
Introduction to Google Productivity Tools for Office and Personal UseIntroduction to Google Productivity Tools for Office and Personal Use
Introduction to Google Productivity Tools for Office and Personal Use
 
Java MCQ Questions and Answers PDF By ScholarHat
Java MCQ Questions and Answers PDF By ScholarHatJava MCQ Questions and Answers PDF By ScholarHat
Java MCQ Questions and Answers PDF By ScholarHat
 
2 Post harvest Physiology of Horticulture produce.pptx
2 Post harvest Physiology of Horticulture  produce.pptx2 Post harvest Physiology of Horticulture  produce.pptx
2 Post harvest Physiology of Horticulture produce.pptx
 
Open Source and AI - ByWater Closing Keynote Presentation.pdf
Open Source and AI - ByWater Closing Keynote Presentation.pdfOpen Source and AI - ByWater Closing Keynote Presentation.pdf
Open Source and AI - ByWater Closing Keynote Presentation.pdf
 
View Inheritance in Odoo 17 - Odoo 17 Slides
View Inheritance in Odoo 17 - Odoo 17  SlidesView Inheritance in Odoo 17 - Odoo 17  Slides
View Inheritance in Odoo 17 - Odoo 17 Slides
 
PRESS RELEASE - UNIVERSITY OF GHANA, JULY 16, 2024.pdf
PRESS RELEASE - UNIVERSITY OF GHANA, JULY 16, 2024.pdfPRESS RELEASE - UNIVERSITY OF GHANA, JULY 16, 2024.pdf
PRESS RELEASE - UNIVERSITY OF GHANA, JULY 16, 2024.pdf
 
How to Manage Shipping Connectors & Shipping Methods in Odoo 17
How to Manage Shipping Connectors & Shipping Methods in Odoo 17How to Manage Shipping Connectors & Shipping Methods in Odoo 17
How to Manage Shipping Connectors & Shipping Methods in Odoo 17
 
Genetics Teaching Plan: Dr.Kshirsagar R.V.
Genetics Teaching Plan: Dr.Kshirsagar R.V.Genetics Teaching Plan: Dr.Kshirsagar R.V.
Genetics Teaching Plan: Dr.Kshirsagar R.V.
 

Chap 9(functions)

  • 1. User-defined Functions Topics  Function and it’s advantages  Form of C Function  Calling function
  • 2. Function and it’s advantages  Function: A set of statement(s) to solve certain kind of problem is called function. Each function has it’s own name. Ex: printf(), scanf(), sqrt() etc.  Advantages of Function in C: 1. The length of source program can be reduced. 2. It is easy to locate and isolate a faulty function. 3. A function may be used by many other function.
  • 3. Classification of Function  Functions can be classified into two categories. 1. Built in function: The function which is build in the C is called built in function. Ex: printf(), scanf(), getch(). 2. User defined function: The functions which are designed by programmer called user defined function.
  • 4. Form of C Function  The form of function: return_type function_name(argument list) { local variable declarations; statement(s); return(expression); }  Here argument list contains valid variable names separated by commas. Return_type is the type of the data returned from function.
  • 5. Continue…  Example of function: int add(int a, int b) { int sum; sum= a+b; return(sum); }
  • 6. Calling of Function  We can call C function by mentioning the name with appropriate argument.  Example of calling: main() { int x=10, y=20,z; z = add(x,y); printf(“Summation = %d”,z); }
  • 7. Call by Value  In this case of function calling, the value of actual parameter is passed to the formal parameter. Here constant value or variable can be used as actual parameter. If we change the value of formal parameter then there is no effect in actual parameter.  void change(int x) { x = x + 10; } main() { int k = 10; change(k); printf(“%d”,k); }
  • 8. Call by Reference  Here the address of actual parameter is passed to the formal parameter. We cannot use address directly. If we change the value of formal parameter then the value of actual parameter also changed.  Void change(int *x) { *x = *x+10; } main() { int k=10; change(&k); printf(“%d”,k); }
  • 9. Nesting of C Function  C permits nesting of functions freely. Function1 can call function2, function2 can call function3,……….and so on.  main() { int a,b,c; function1(); } function1() { ……. function2(); } function2() { ……… }
  • 10. Recursion  When a function calls itself is called recursion. Simple example-  main() { printf(“This is Recursion”); main(); }  When executed, the output like This is Recursion This is Recursion This is
  • 11. Continue..  A recursive function for factorial: int factorial(int n) { if(n==0) return(1); else return(n*factorial(n-1)); }
  • 12. Function with Array  Like the values of simple variables, it is also possible to pass the values of an array to a function.  main() { static int value[ ]={10,45,25,40}; printf(“Largest value: %d”,maximum(value,4)); } int maximum(int x[ ], int n) { int i, max=0; for(i=0;i<n;i++) if(max<x[i]) max=x[i]; return(max); }