SlideShare ist ein Scribd-Unternehmen logo
1 von 21
UUSSEERR DDEEFFIINNEE 
FFUUNNCCTTIIOONNSS
• Definition - function 
• 
●A set of statements working together with 
• common goal is known as function. 
• 
Also known as subprograms which are used to 
●• compute a value or perform a specific task. 
• 
They can’t run independently and are always 
●• called by the main() program or by some other 
• function. 
2
Functions 
Function: 
The strength of C language is to define and use function. 
The strength of C language is that C function are easy to define and 
use. 
Function 
Library User define 
function function
Library function: 
The library function are not required to be written 
by us. 
Eg: 
printf 
scanf
User define function: 
User defined functions are self-contained blocks 
of statements which are written by the user to 
compute or perform a task. 
●They can be called by the main program 
repeatedly as per the requirement. 
Eg: main() 
‘main’ is specially used function in C. Ever program must have main 
function to indicate, where the program begins its execution. When a 
program to large and complex then the result of debugging testing 
and maintaining becomes difficult.
Main program 
Function A function B functionC 
B1 B2
UUssiinngg FFuunnccttiioonnss 
• The main functions and other library functions does 
need to be declared and defined but the main 
function’s body need to be defined by the 
programmer.
TThhee 33 ccoommppoonneennttss aassssoocciiaatteedd 
wwiitthh ffuunnccttiioonnss aarree:: 
1. The Declaration 
2. The function definition 
3. The Calling Statement
FFuunnccttiioonn DDeeccllaarraattiioonn 
• In C user- written functions should normally be 
declared prior to its use to allow compiler to 
perform type checking on arguments used in its call 
statement. 
• The general form is: 
• Retirn_data_type function_name (data_type 
Var_name, …..);
 Function name: this is the name given to the 
function. It follows the same naming convention as 
that of any valid variable in C. 
 Return data type: this specifies the type of data 
given back to the calling construct. 
Data type list: this list specifies the data type of 
each variables, the values of which are expected 
to be transmitted to the function. These variables 
are known as formal parameters.
NNoottee:: 
• It is possible not to declare functions prior to the use 
but the error checking will not be performed. 
• ; is required at the end of function declaration. 
• E.g. int FindMax(int x, int y);
FFuunnccttiioonn DDeeffiinniittiioonn 
 The collection of program statements that does a 
specific tasks done by the function is called the 
function definition. 
 It conist of function header: 
◦ Int FindMax(int x, int y) 
◦ { 
◦ } 
 and function body. 
 Int FindMax(int x, int y) 
 { 
 //body of the function…. 
 }
FFLLOOWW OOFF FFUUNNCCTTIIOONN 
• ●When the program is executed (that is, run) execution always begins at 
• the first statement in the function main no matter where it is placed in the 
• program. 
• ●Other functions are executed only when they are called. 
• ●Function prototypes appear before any function definition, so the 
• compiler translates these first. The compiler can then correctly translate a 
• function call. 
• ●A function call statement results in the transfer of control to the first 
• statement in the body of the called function. 
• ●After the last statement of the called function is executed, the control is 
• passed back to the point immediately following the function call. 
• ●A value-returning function returns a value. Therefore, for value-returning 
• functions, after executing the function when the control goes back to the 
• caller, the value that the function returns replaces the function call 
• statement.
FFuunnccttiioonn ccaallll 
• The function is called from the main() 
• The function can in turn call a another function. 
• the function call statements invokes the function, which 
means the program control passes to that function. Once the 
function completes its task, the program control is passed 
back to the calling environment. 
• The general form of calling stmt is: 
• Function_name (var1, var2,..); 
• Or 
• var_name=function name(var1, var2,..);
SSaalliieenntt ppooiinnttss ttoo bbee ttaakkeenn 
iinnttoo ccoonnssiiddeerraattiioonn 
• The func name and the type and number of 
arguments must match with that of the function 
declaration stmt and the header of the function 
definition. 
• Arguments present in the form of expression are 
evaluated and converted to the type of formal 
parameters at the beginning of the body of the 
function.
PPaassssiinngg ooff aarrgguummeennttss ttoo 
tthhee ffuunnccttiioonn 
1. Call by value or pass by value: 
1. When arguments are passed by values this means that local copies of 
the values of the arguments are passed to the function. 
2. Call by reference or pass by reference. 
1. The address of the variable is passed as value of parameters to the 
function.
Passing arrays to 
functions 
• Arrays can also be the arguments of function 
• Only the base address of the array is passed to the 
function 
• Hence the passing of arguments is done by 
reference. 
• When arrays is passed as arguments then actual 
contents of the arrays is altered.
RReeccuurrssiivvee FFuunnccttiioonnss.. 
• Recursion in programming is a technique for 
defining a problem in terms of one or more smaller 
versions of the problem. 
• A recursive function is one that calls itself directly or 
indirectly to solve a smaller version of its task until a 
final call which does not require a self call.
TThhee mmeecchhaanniiccss ooff 
rreeccuurrssiivvee ccaallll 
• Start main program 
• ….. 
• 1st call to print backward 
• enter a char : H 
o 2nd call to print_backward 
• enter a char: i. 
• 3rd call to print_backward 
• enter a char: . 
• //now it will not call againcoz its ‘.’ 
• 3rd call finish 
• print i. 
• 2nd call finish 
• Print H. 
First call Finish… 
… 
End of main program………
HHooww rreeccuurrssiioonn iiss 
iimmpplleemmeenntteedd.. 
• The storage mechanism in most modern languages 
is stack storage mgmt. 
• In this mechanism the program’s data area is 
allocated at load time. 
• While storage for functions data is allocated when 
function is invoked. 
• On exit from function this storage is de-allocated. 
• This results in a runtime stack. 
• In recursive cases one call does not overlap with 
the other.
WWhhaatt iiss nneeeedd ffoorr 
iimmpplleemmeennttiinngg rreeccuurrssiioonn 
• Decomposition into smaller problems of same size. 
• Recursive call must diminish problem size. 
• Necessity of base case. 
• Base case must be reached.

Weitere ähnliche Inhalte

Was ist angesagt?

Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT03062679929
 
Type casting in java
Type casting in javaType casting in java
Type casting in javaFarooq Baloch
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methodsShubham Dwivedi
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptAmanuelZewdie4
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)Ritika Sharma
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in CHarendra Singh
 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaCPD INDIA
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in clavanya marichamy
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonSujith Kumar
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsMayank Jain
 
Functions in python
Functions in pythonFunctions in python
Functions in pythoncolorsof
 

Was ist angesagt? (20)

Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Functions in c
Functions in cFunctions in c
Functions in c
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Function
FunctionFunction
Function
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
 
Strings in C
Strings in CStrings in C
Strings in C
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 

Ähnlich wie user defined function

358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2sumitbardhan
 
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdfManiMala75
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C ProgrammingAnil Pokhrel
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxGebruGetachew2
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxsangeeta borde
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxKhurramKhan173
 
Chapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfChapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfTeshaleSiyum
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdfTeshaleSiyum
 
Functions in c language1
Functions in c language1Functions in c language1
Functions in c language1sirikeshava
 
Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiSowmya Jyothi
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxSKUP1
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxLECO9
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 

Ähnlich wie user defined function (20)

358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2
 
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptx
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
Chapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfChapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdf
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdf
 
Unit iii
Unit iiiUnit iii
Unit iii
 
Lecture6
Lecture6Lecture6
Lecture6
 
Functions in c language1
Functions in c language1Functions in c language1
Functions in c language1
 
Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
 
Basic c++
Basic c++Basic c++
Basic c++
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptx
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptx
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Functions
FunctionsFunctions
Functions
 

Kürzlich hochgeladen

A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projectssmsksolar
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 

Kürzlich hochgeladen (20)

A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 

user defined function

  • 2. • Definition - function • ●A set of statements working together with • common goal is known as function. • Also known as subprograms which are used to ●• compute a value or perform a specific task. • They can’t run independently and are always ●• called by the main() program or by some other • function. 2
  • 3. Functions Function: The strength of C language is to define and use function. The strength of C language is that C function are easy to define and use. Function Library User define function function
  • 4. Library function: The library function are not required to be written by us. Eg: printf scanf
  • 5. User define function: User defined functions are self-contained blocks of statements which are written by the user to compute or perform a task. ●They can be called by the main program repeatedly as per the requirement. Eg: main() ‘main’ is specially used function in C. Ever program must have main function to indicate, where the program begins its execution. When a program to large and complex then the result of debugging testing and maintaining becomes difficult.
  • 6. Main program Function A function B functionC B1 B2
  • 7. UUssiinngg FFuunnccttiioonnss • The main functions and other library functions does need to be declared and defined but the main function’s body need to be defined by the programmer.
  • 8. TThhee 33 ccoommppoonneennttss aassssoocciiaatteedd wwiitthh ffuunnccttiioonnss aarree:: 1. The Declaration 2. The function definition 3. The Calling Statement
  • 9. FFuunnccttiioonn DDeeccllaarraattiioonn • In C user- written functions should normally be declared prior to its use to allow compiler to perform type checking on arguments used in its call statement. • The general form is: • Retirn_data_type function_name (data_type Var_name, …..);
  • 10.  Function name: this is the name given to the function. It follows the same naming convention as that of any valid variable in C.  Return data type: this specifies the type of data given back to the calling construct. Data type list: this list specifies the data type of each variables, the values of which are expected to be transmitted to the function. These variables are known as formal parameters.
  • 11. NNoottee:: • It is possible not to declare functions prior to the use but the error checking will not be performed. • ; is required at the end of function declaration. • E.g. int FindMax(int x, int y);
  • 12. FFuunnccttiioonn DDeeffiinniittiioonn  The collection of program statements that does a specific tasks done by the function is called the function definition.  It conist of function header: ◦ Int FindMax(int x, int y) ◦ { ◦ }  and function body.  Int FindMax(int x, int y)  {  //body of the function….  }
  • 13. FFLLOOWW OOFF FFUUNNCCTTIIOONN • ●When the program is executed (that is, run) execution always begins at • the first statement in the function main no matter where it is placed in the • program. • ●Other functions are executed only when they are called. • ●Function prototypes appear before any function definition, so the • compiler translates these first. The compiler can then correctly translate a • function call. • ●A function call statement results in the transfer of control to the first • statement in the body of the called function. • ●After the last statement of the called function is executed, the control is • passed back to the point immediately following the function call. • ●A value-returning function returns a value. Therefore, for value-returning • functions, after executing the function when the control goes back to the • caller, the value that the function returns replaces the function call • statement.
  • 14. FFuunnccttiioonn ccaallll • The function is called from the main() • The function can in turn call a another function. • the function call statements invokes the function, which means the program control passes to that function. Once the function completes its task, the program control is passed back to the calling environment. • The general form of calling stmt is: • Function_name (var1, var2,..); • Or • var_name=function name(var1, var2,..);
  • 15. SSaalliieenntt ppooiinnttss ttoo bbee ttaakkeenn iinnttoo ccoonnssiiddeerraattiioonn • The func name and the type and number of arguments must match with that of the function declaration stmt and the header of the function definition. • Arguments present in the form of expression are evaluated and converted to the type of formal parameters at the beginning of the body of the function.
  • 16. PPaassssiinngg ooff aarrgguummeennttss ttoo tthhee ffuunnccttiioonn 1. Call by value or pass by value: 1. When arguments are passed by values this means that local copies of the values of the arguments are passed to the function. 2. Call by reference or pass by reference. 1. The address of the variable is passed as value of parameters to the function.
  • 17. Passing arrays to functions • Arrays can also be the arguments of function • Only the base address of the array is passed to the function • Hence the passing of arguments is done by reference. • When arrays is passed as arguments then actual contents of the arrays is altered.
  • 18. RReeccuurrssiivvee FFuunnccttiioonnss.. • Recursion in programming is a technique for defining a problem in terms of one or more smaller versions of the problem. • A recursive function is one that calls itself directly or indirectly to solve a smaller version of its task until a final call which does not require a self call.
  • 19. TThhee mmeecchhaanniiccss ooff rreeccuurrssiivvee ccaallll • Start main program • ….. • 1st call to print backward • enter a char : H o 2nd call to print_backward • enter a char: i. • 3rd call to print_backward • enter a char: . • //now it will not call againcoz its ‘.’ • 3rd call finish • print i. • 2nd call finish • Print H. First call Finish… … End of main program………
  • 20. HHooww rreeccuurrssiioonn iiss iimmpplleemmeenntteedd.. • The storage mechanism in most modern languages is stack storage mgmt. • In this mechanism the program’s data area is allocated at load time. • While storage for functions data is allocated when function is invoked. • On exit from function this storage is de-allocated. • This results in a runtime stack. • In recursive cases one call does not overlap with the other.
  • 21. WWhhaatt iiss nneeeedd ffoorr iimmpplleemmeennttiinngg rreeccuurrssiioonn • Decomposition into smaller problems of same size. • Recursive call must diminish problem size. • Necessity of base case. • Base case must be reached.