SlideShare a Scribd company logo
FUNCTIONS IN C LANGUAGE
By
CH SRILAKSHMI PRASANNA MTech(PhD)
INTRODUCTION TO FUNCTIONS
 A large program in C can be divided to many subprogram.
 A function is a self contained sub program which does a specific task.
 A C program consists of one or more functions.
 A functions can also be termed as method, sub routine, procedure.
 A C program must contain at least one function it must be main() function.
 Classification of Function User defined function
 Library function
INTRODUCTION TO FUNCTIONS
Library Functions:
• already defined in the system libraries.
• Programmer can reuse the existing
code in the system libraries
which is helpful to write error free code.
• User must be aware
of syntax of the function.
INTRODUCTION TO FUNCTIONS
Library Functions:
INTRODUCTION TO FUNCTIONS
Library Functions:
INTRODUCTION TO FUNCTIONS
User defined Functions:
In C programming language, users can also create their own
functions. The functions that are created by users are called as user
defined functions.
The user defined functions are of 4 types:
Function without Parameters(arguments) and without Return value
Function with Parameters(arguments) and without Return value
Function without Parameters(arguments) and with Return value
Function with Parameters(arguments) and with Return value
INTRODUCTION TO FUNCTIONS
Syntax:
return_type function_name (datatype parameter)
{
local variable declaration;
statement1;
statement2;
---------------
return statement;
}
INTRODUCTION TO FUNCTIONS
 A function declaration tells the compiler about a function name and how to call the
function.
Calling
function
Called
function
INTRODUCTION TO FUNCTIONS
 The Function which calls another Function is called Calling Function and
 Function which is called by another Function is call Called Function.
INTRODUCTION TO FUNCTIONS
Advantage of functions in C:
• By using functions, we can avoid rewriting same logic/code again and again in a
program.
• We can call C functions any number of times in a program and from any place in a
program.
• We can track a large C program easily when it is divided into multiple functions.
• Reusability is the main achievement of C functions.
FUNCTION WITHOUT PARAMETERS AND WITHOUT
RETURN VALUE
In this type of functions there is no
data transfer between calling function
and called function. Simply the
execution control jumps from calling-
function to called function and
executes called function, and finally
comes back to the calling function.
FUNCTION WITH PARAMETERS AND WITHOUT RETURN
VALUE
In this type of functions there is data
transfer from calling-function to called
function (parameters) but there is no data
transfer from called function to calling-
function (return value). The execution
control jumps from calling-function to
called function along with the parameters
and executes called function, and finally
comes back to the calling function.
Actual: num1,num2
Formal: a, b
FUNCTION WITH PARAMETERS AND WITHOUT RETURN
VALUE
The parameters(arguments) specified in calling function are said
to be Actual Parameters (arguments).
The parameters(arguments) declared in called function are said
to be Formal Parameters(arguments).
The value of actual parameters(arguments) is always copied into
formal parameters(arguments).
FUNCTION WITH PARAMETERS AND WITHOUT RETURN
VALUE
In C Programming Language, there are two methods to pass
parameters from calling function to called function and they are
as follows...
Call by Value
Call by Reference
FUNCTION WITH PARAMETERS AND WITHOUT RETURN
VALUE
In call by value parameter passing method, th
copy of actual parameter values are copied t
formal parameters and these formal parameter
are used in called function. The changes made on
the formal parameters does not effect the value
of actual parameters. That means, after th
execution control comes back to the callin
function, the actual parameter values remain
same.
the variables num1 and num2 are called
actual parameters and the variables a and b
are called formal parameters. The value of
num1 is copied into a and the value of
num2 is copied into b. The changes made
FUNCTION WITH PARAMETERS AND WITHOUT RETURN
VALUE
Call by Reference
In call by reference parameter passing
method, the address of the actual
parameters is passed to the called
function and is received by the formal
parameters (pointers). Whenever we use
these formal parameters in called
function, they directly access the
memory locations of actual parameters.
So the changes made on the formal
parameters effects the values of actual
parameters.
The addresses of variables num1 and
num2 are copied to pointer variables
a and b. The changes made on the
pointer variables a and b in called
function effects the values of actual
parameters num1 and num2 in calling
FUNCTION WITHOUT PARAMETERS AND WITH RETURN
VALUE
In this type of functions there is no data transfer
from calling-function to called-function
(parameters) but there is data transfer from
called function to calling-function (return value).
The execution control jumps from calling-
function to called function and executes called
function, and finally comes back to the calling
function along with a return value.
FUNCTION WITH PARAMETERS AND WITH RETURN
VALUE
In this type of functions there is data
transfer from calling-function to called-
function (parameters) and also from
called function to calling-function
(return value). The execution control
jumps from calling-function to called
function along with parameters and
executes called function, and finally
comes back to the calling function
along with a return value.
RECURSIVE FUNCTIONS IN C
In C programming language, function calls can be made from the
main() function, other functions or from the same function itself.
A function called by itself is called recursive function.
When a function is called by itself, the first call remains under execution
till the last call gets invoked. Every time when a function call is invoked,
the function returns the execution control to the previous function call.
RECURSIVE FUNCTIONS IN C
When a function is called by
itself, the first call remains under
execution till the last call gets
invoked. Every time when a
function call is invoked, the
function returns the execution
control to the previous function
call.

More Related Content

What's hot

Notes: Verilog Part 5 - Tasks and Functions
Notes: Verilog Part 5 - Tasks and FunctionsNotes: Verilog Part 5 - Tasks and Functions
Notes: Verilog Part 5 - Tasks and Functions
Jay Baxi
 
Presentation of computer
Presentation of computerPresentation of computer
Presentation of computer
SabinDhakal13
 
Basic c++
Basic c++Basic c++
Ch9 Functions
Ch9 FunctionsCh9 Functions
Ch9 Functions
SzeChingChen
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
Jenish Patel
 
Ch10 Program Organization
Ch10 Program OrganizationCh10 Program Organization
Ch10 Program Organization
SzeChingChen
 
structured programming
structured programmingstructured programming
structured programming
Ahmad54321
 
Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)
Calvin Cheng
 
structure of a c program
structure of a c programstructure of a c program
structure of a c program
sruthi yandapalli
 
Functions
FunctionsFunctions
Functions
Mitali Chugh
 
Functions
FunctionsFunctions
Functions
Mitali Chugh
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macros
Anand Kumar
 
09 implementing+subprograms
09 implementing+subprograms09 implementing+subprograms
09 implementing+subprograms
baran19901990
 
Function Returns
Function ReturnsFunction Returns
Function Returns
primeteacher32
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
Learn By Watch
 
Command Line Arguments in C#
Command Line Arguments in C#Command Line Arguments in C#
Command Line Arguments in C#
Ali Hassan
 
What's New In C# 5.0 - Programar 2013
What's New In C# 5.0 - Programar 2013What's New In C# 5.0 - Programar 2013
What's New In C# 5.0 - Programar 2013
Paulo Morgado
 
Verilog Tasks and functions
Verilog Tasks and functionsVerilog Tasks and functions
Verilog Tasks and functions
Vinchipsytm Vlsitraining
 
Inline functions
Inline functionsInline functions
Inline functions
DhwaniHingorani
 

What's hot (20)

Notes: Verilog Part 5 - Tasks and Functions
Notes: Verilog Part 5 - Tasks and FunctionsNotes: Verilog Part 5 - Tasks and Functions
Notes: Verilog Part 5 - Tasks and Functions
 
Presentation of computer
Presentation of computerPresentation of computer
Presentation of computer
 
Basic c++
Basic c++Basic c++
Basic c++
 
Ch9 Functions
Ch9 FunctionsCh9 Functions
Ch9 Functions
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
 
Ch10 Program Organization
Ch10 Program OrganizationCh10 Program Organization
Ch10 Program Organization
 
structured programming
structured programmingstructured programming
structured programming
 
Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)
 
structure of a c program
structure of a c programstructure of a c program
structure of a c program
 
Functions
FunctionsFunctions
Functions
 
Functions
FunctionsFunctions
Functions
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macros
 
09 implementing+subprograms
09 implementing+subprograms09 implementing+subprograms
09 implementing+subprograms
 
Function Returns
Function ReturnsFunction Returns
Function Returns
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
 
Command Line Arguments in C#
Command Line Arguments in C#Command Line Arguments in C#
Command Line Arguments in C#
 
Savitch ch 05
Savitch ch 05Savitch ch 05
Savitch ch 05
 
What's New In C# 5.0 - Programar 2013
What's New In C# 5.0 - Programar 2013What's New In C# 5.0 - Programar 2013
What's New In C# 5.0 - Programar 2013
 
Verilog Tasks and functions
Verilog Tasks and functionsVerilog Tasks and functions
Verilog Tasks and functions
 
Inline functions
Inline functionsInline functions
Inline functions
 

Similar to Functions in c language1

CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptx
GebruGetachew2
 
Functions
Functions Functions
Functions
Praneeth960856
 
C functions
C functionsC functions
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
ArshiniGubbala3
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
zueZ3
 
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
sumitbardhan
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
Bharath904863
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
Tanmay Modi
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Modular Programming in C
Modular Programming in CModular Programming in C
Modular Programming in C
bhawna kol
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdf
TeshaleSiyum
 
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
TeshaleSiyum
 
Functions.pptx
Functions.pptxFunctions.pptx
Functions.pptx
AkshayKumarK14
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
Rhishav Poudyal
 
user defined function
user defined functionuser defined function
user defined function
King Kavin Patel
 
Function in C
Function in CFunction in C
Function in C
Dr. Abhineet Anand
 
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 in c++, presentation, short and sweet presentation, and details of ...
Functions in c++, presentation, short and sweet presentation, and details of ...Functions in c++, presentation, short and sweet presentation, and details of ...
Functions in c++, presentation, short and sweet presentation, and details of ...
Sar
 

Similar to Functions in c language1 (20)

CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptx
 
Functions
Functions Functions
Functions
 
C functions
C functionsC functions
C functions
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
 
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
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Modular Programming in C
Modular Programming in CModular Programming in C
Modular Programming in C
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdf
 
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
 
Functions.pptx
Functions.pptxFunctions.pptx
Functions.pptx
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
 
user defined function
user defined functionuser defined function
user defined function
 
Function in C
Function in CFunction in C
Function in C
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdf
 
Functions in c++, presentation, short and sweet presentation, and details of ...
Functions in c++, presentation, short and sweet presentation, and details of ...Functions in c++, presentation, short and sweet presentation, and details of ...
Functions in c++, presentation, short and sweet presentation, and details of ...
 

More from sirikeshava

Python programming
Python programmingPython programming
Python programming
sirikeshava
 
Siri linux installation
Siri linux installationSiri linux installation
Siri linux installation
sirikeshava
 
Siri hardware troubleshooting
Siri hardware troubleshootingSiri hardware troubleshooting
Siri hardware troubleshooting
sirikeshava
 
Siri softwaretroubleshooting.doc
Siri softwaretroubleshooting.docSiri softwaretroubleshooting.doc
Siri softwaretroubleshooting.doc
sirikeshava
 
Siri bootcamp
Siri bootcampSiri bootcamp
Siri bootcamp
sirikeshava
 
Week8 siri
Week8 siriWeek8 siri
Week8 siri
sirikeshava
 
IT Workshop PC-HARDWARE Week3
IT Workshop PC-HARDWARE Week3IT Workshop PC-HARDWARE Week3
IT Workshop PC-HARDWARE Week3
sirikeshava
 
QOS oriented vho scheme for wifi and wimax overlay networks
QOS oriented vho scheme for wifi and wimax overlay networksQOS oriented vho scheme for wifi and wimax overlay networks
QOS oriented vho scheme for wifi and wimax overlay networks
sirikeshava
 

More from sirikeshava (8)

Python programming
Python programmingPython programming
Python programming
 
Siri linux installation
Siri linux installationSiri linux installation
Siri linux installation
 
Siri hardware troubleshooting
Siri hardware troubleshootingSiri hardware troubleshooting
Siri hardware troubleshooting
 
Siri softwaretroubleshooting.doc
Siri softwaretroubleshooting.docSiri softwaretroubleshooting.doc
Siri softwaretroubleshooting.doc
 
Siri bootcamp
Siri bootcampSiri bootcamp
Siri bootcamp
 
Week8 siri
Week8 siriWeek8 siri
Week8 siri
 
IT Workshop PC-HARDWARE Week3
IT Workshop PC-HARDWARE Week3IT Workshop PC-HARDWARE Week3
IT Workshop PC-HARDWARE Week3
 
QOS oriented vho scheme for wifi and wimax overlay networks
QOS oriented vho scheme for wifi and wimax overlay networksQOS oriented vho scheme for wifi and wimax overlay networks
QOS oriented vho scheme for wifi and wimax overlay networks
 

Recently uploaded

Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
PrashantGoswami42
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
MuhammadTufail242431
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
ShahidSultan24
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 

Recently uploaded (20)

Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 

Functions in c language1

  • 1. FUNCTIONS IN C LANGUAGE By CH SRILAKSHMI PRASANNA MTech(PhD)
  • 2. INTRODUCTION TO FUNCTIONS  A large program in C can be divided to many subprogram.  A function is a self contained sub program which does a specific task.  A C program consists of one or more functions.  A functions can also be termed as method, sub routine, procedure.  A C program must contain at least one function it must be main() function.  Classification of Function User defined function  Library function
  • 3. INTRODUCTION TO FUNCTIONS Library Functions: • already defined in the system libraries. • Programmer can reuse the existing code in the system libraries which is helpful to write error free code. • User must be aware of syntax of the function.
  • 6. INTRODUCTION TO FUNCTIONS User defined Functions: In C programming language, users can also create their own functions. The functions that are created by users are called as user defined functions. The user defined functions are of 4 types: Function without Parameters(arguments) and without Return value Function with Parameters(arguments) and without Return value Function without Parameters(arguments) and with Return value Function with Parameters(arguments) and with Return value
  • 7. INTRODUCTION TO FUNCTIONS Syntax: return_type function_name (datatype parameter) { local variable declaration; statement1; statement2; --------------- return statement; }
  • 8. INTRODUCTION TO FUNCTIONS  A function declaration tells the compiler about a function name and how to call the function. Calling function Called function
  • 9. INTRODUCTION TO FUNCTIONS  The Function which calls another Function is called Calling Function and  Function which is called by another Function is call Called Function.
  • 10. INTRODUCTION TO FUNCTIONS Advantage of functions in C: • By using functions, we can avoid rewriting same logic/code again and again in a program. • We can call C functions any number of times in a program and from any place in a program. • We can track a large C program easily when it is divided into multiple functions. • Reusability is the main achievement of C functions.
  • 11. FUNCTION WITHOUT PARAMETERS AND WITHOUT RETURN VALUE In this type of functions there is no data transfer between calling function and called function. Simply the execution control jumps from calling- function to called function and executes called function, and finally comes back to the calling function.
  • 12. FUNCTION WITH PARAMETERS AND WITHOUT RETURN VALUE In this type of functions there is data transfer from calling-function to called function (parameters) but there is no data transfer from called function to calling- function (return value). The execution control jumps from calling-function to called function along with the parameters and executes called function, and finally comes back to the calling function. Actual: num1,num2 Formal: a, b
  • 13. FUNCTION WITH PARAMETERS AND WITHOUT RETURN VALUE The parameters(arguments) specified in calling function are said to be Actual Parameters (arguments). The parameters(arguments) declared in called function are said to be Formal Parameters(arguments). The value of actual parameters(arguments) is always copied into formal parameters(arguments).
  • 14. FUNCTION WITH PARAMETERS AND WITHOUT RETURN VALUE In C Programming Language, there are two methods to pass parameters from calling function to called function and they are as follows... Call by Value Call by Reference
  • 15. FUNCTION WITH PARAMETERS AND WITHOUT RETURN VALUE In call by value parameter passing method, th copy of actual parameter values are copied t formal parameters and these formal parameter are used in called function. The changes made on the formal parameters does not effect the value of actual parameters. That means, after th execution control comes back to the callin function, the actual parameter values remain same. the variables num1 and num2 are called actual parameters and the variables a and b are called formal parameters. The value of num1 is copied into a and the value of num2 is copied into b. The changes made
  • 16. FUNCTION WITH PARAMETERS AND WITHOUT RETURN VALUE Call by Reference In call by reference parameter passing method, the address of the actual parameters is passed to the called function and is received by the formal parameters (pointers). Whenever we use these formal parameters in called function, they directly access the memory locations of actual parameters. So the changes made on the formal parameters effects the values of actual parameters. The addresses of variables num1 and num2 are copied to pointer variables a and b. The changes made on the pointer variables a and b in called function effects the values of actual parameters num1 and num2 in calling
  • 17. FUNCTION WITHOUT PARAMETERS AND WITH RETURN VALUE In this type of functions there is no data transfer from calling-function to called-function (parameters) but there is data transfer from called function to calling-function (return value). The execution control jumps from calling- function to called function and executes called function, and finally comes back to the calling function along with a return value.
  • 18. FUNCTION WITH PARAMETERS AND WITH RETURN VALUE In this type of functions there is data transfer from calling-function to called- function (parameters) and also from called function to calling-function (return value). The execution control jumps from calling-function to called function along with parameters and executes called function, and finally comes back to the calling function along with a return value.
  • 19. RECURSIVE FUNCTIONS IN C In C programming language, function calls can be made from the main() function, other functions or from the same function itself. A function called by itself is called recursive function. When a function is called by itself, the first call remains under execution till the last call gets invoked. Every time when a function call is invoked, the function returns the execution control to the previous function call.
  • 20. RECURSIVE FUNCTIONS IN C When a function is called by itself, the first call remains under execution till the last call gets invoked. Every time when a function call is invoked, the function returns the execution control to the previous function call.