SlideShare a Scribd company logo
1 of 20
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 FunctionsJay Baxi
 
Presentation of computer
Presentation of computerPresentation of computer
Presentation of computerSabinDhakal13
 
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 OrganizationSzeChingChen
 
structured programming
structured programmingstructured programming
structured programmingAhmad54321
 
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
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macrosAnand Kumar
 
09 implementing+subprograms
09 implementing+subprograms09 implementing+subprograms
09 implementing+subprogramsbaran19901990
 
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 2013Paulo Morgado
 

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.pptxGebruGetachew2
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptxzueZ3
 
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
 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c languageTanmay Modi
 
Modular Programming in C
Modular Programming in CModular Programming in C
Modular Programming in Cbhawna kol
 
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
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptxRhishav Poudyal
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfBoomBoomers
 
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 language Functions in c language
Functions in c language
 
Functions in c language
Functions in c languageFunctions 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++[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
 
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 programmingsirikeshava
 
Siri linux installation
Siri linux installationSiri linux installation
Siri linux installationsirikeshava
 
Siri hardware troubleshooting
Siri hardware troubleshootingSiri hardware troubleshooting
Siri hardware troubleshootingsirikeshava
 
Siri softwaretroubleshooting.doc
Siri softwaretroubleshooting.docSiri softwaretroubleshooting.doc
Siri softwaretroubleshooting.docsirikeshava
 
IT Workshop PC-HARDWARE Week3
IT Workshop PC-HARDWARE Week3IT Workshop PC-HARDWARE Week3
IT Workshop PC-HARDWARE Week3sirikeshava
 
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 networkssirikeshava
 

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

Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 

Recently uploaded (20)

Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 

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.