SlideShare ist ein Scribd-Unternehmen logo
1 von 22
INTRODUCTION TO FUNCTIONS
TYPES OF FUNCTIONS
ELEMENTS OF USER DEFINED FUNCTIONS
TYPES ON THE BASIS OF ARGUMENTS AND
RETURN VALUES
METHODS OF CALLING A FUNCTION
Functions
Introduction to Function
Block of statements that perform the particular task.
Enables modular programming.
Main() is the driver function.
Has pre defined prototype.
Same function can be accessed from different places
within a program.
Once a function execution is completed , control
return to the place from where the function was
called.
Advantages
Modular Programming
Length of source program can be reduced
Easy to locate and isolate faulty function
Functions can be used by other program’s
Types of Functions
Library (Built In) Functions:
 They are written in the header files.
 To use them appropriate header files should be included.
Header Files Functions Defined
stdio.h Printf(), scanf(), getchar(), putchar(),
gets(), puts(), fopen(), fclose()
conio.h Clrscr(), getch()
Ctype.h Toupper(), tolower(), isalpha()
Math.h Pow(), sqrt(), cos(), log()
Stdlib.h Rand(), exit()
String.h Strlen(), strcpy(), strupr()
User Defined Functions
 Written by the user at the time of programming.
Elements of User defined functions
Function Prototype
Function Call
Function arguments and parameters
Function Definitions
Function prototype
It specify the type of value that is to be return from
the function and that is to be passed to the function.
It is defined in the beginning before the function call
is made.
Syntax:
 return-type name-of-function(list of arguments);
 Example
Void sum(int, int);
Function Call
A function can be called by specifying name and list
of arguments enclosed in parenthesis and separated
by comma.
If there is no arguments empty parenthesis are place
after function name.
If function return a value, function call is written as
assignment statement as:
 A=sum(x,y);
Function arguments and parameters
Arguments are also called actual parameters.
Arguments are written within parenthesis at the time
of function call.
Parameters are also called formal parameters.
These are written within parenthesis at the time of
function definition.
Function Definition
It is the independent program module.
It is written to specify the particular task that is to be
performed by the function.
The first line of the function is called function
declarator and rest line inside { } is called function
body
Return statement
It is the last statement of the function that return
certain values.
It return certain types of values to the place from
where the function was invoked.
Syntax:
 return(variable-name or constant);
Categories of function
Function with no arguments and no return
Function with arguments but no return
Function with no arguments and return
Function with arguments and return
Function with no argument and no return
Function with argument and no return
Function with no argument and return
Function with argument and return
Methods of calling function
Call by value
Call by reference
Call by value
Copies the value of actual parameters into formal
parameters.
During execution whatever changes are made in the
formal parameters are not reflected back in the
actual parameters.
Call by Reference
Reference(address) of the original variable is passed.
Function does not create its own copy, it refers to the
original values by reference.
Functions works with the original data and changes
are made in the original data.
Functions in C

Weitere ähnliche Inhalte

Was ist angesagt?

Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT03062679929
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointersSamiksha Pun
 
Inline function
Inline functionInline function
Inline functionTech_MX
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C v_jk
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of ConstructorsDhrumil Panchal
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)Ritika Sharma
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++HalaiHansaika
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator OverloadingNilesh Dalvi
 
Type casting in java
Type casting in javaType casting in java
Type casting in javaFarooq Baloch
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++Vraj Patel
 

Was ist angesagt? (20)

Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
Structure in C
Structure in CStructure in C
Structure in C
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
stack & queue
stack & queuestack & queue
stack & queue
 
Inline function
Inline functionInline function
Inline function
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
Array in c++
Array in c++Array in c++
Array in c++
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Type casting in java
Type casting in javaType casting in java
Type casting in java
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 

Andere mochten auch

Andere mochten auch (10)

Function in C Language
Function in C Language Function in C Language
Function in C Language
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
 
Function in c
Function in cFunction in c
Function in c
 
Loops Basics
Loops BasicsLoops Basics
Loops Basics
 
Function in C
Function in CFunction in C
Function in C
 
user defined function
user defined functionuser defined function
user defined function
 
Loops in C
Loops in CLoops in C
Loops in C
 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C Programming
 
String c
String cString c
String c
 
String in c
String in cString in c
String in c
 

Ähnlich wie Functions in C

function of C.pptx
function of C.pptxfunction of C.pptx
function of C.pptxshivas379526
 
D-38 vedant ICCPL.pptx
D-38 vedant ICCPL.pptxD-38 vedant ICCPL.pptx
D-38 vedant ICCPL.pptxVedantSahane
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptxRhishav Poudyal
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1YOGESH SINGH
 
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1Jeevan Raj
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptxManas40552
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxSangeetaBorde3
 
Functions in C++
Functions in C++Functions in C++
Functions in C++home
 
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
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functionsnikshaikh786
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)Mansi Tyagi
 

Ähnlich wie Functions in C (20)

function of C.pptx
function of C.pptxfunction of C.pptx
function of C.pptx
 
D-38 vedant ICCPL.pptx
D-38 vedant ICCPL.pptxD-38 vedant ICCPL.pptx
D-38 vedant ICCPL.pptx
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
 
4. function
4. function4. function
4. function
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
 
Functions in c
Functions in cFunctions in c
Functions in c
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
 
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1
 
Functions
Functions Functions
Functions
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Functions
FunctionsFunctions
Functions
 
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
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functions
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 

Mehr von Kamal Acharya

Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computerKamal Acharya
 
Introduction to Computer Security
Introduction to Computer SecurityIntroduction to Computer Security
Introduction to Computer SecurityKamal Acharya
 
Making decision and repeating in PHP
Making decision and repeating  in PHPMaking decision and repeating  in PHP
Making decision and repeating in PHPKamal Acharya
 
Working with arrays in php
Working with arrays in phpWorking with arrays in php
Working with arrays in phpKamal Acharya
 
Text and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHPText and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHPKamal Acharya
 
Capacity Planning of Data Warehousing
Capacity Planning of Data WarehousingCapacity Planning of Data Warehousing
Capacity Planning of Data WarehousingKamal Acharya
 
Information Privacy and Data Mining
Information Privacy and Data MiningInformation Privacy and Data Mining
Information Privacy and Data MiningKamal Acharya
 
Association Analysis in Data Mining
Association Analysis in Data MiningAssociation Analysis in Data Mining
Association Analysis in Data MiningKamal Acharya
 
Classification techniques in data mining
Classification techniques in data miningClassification techniques in data mining
Classification techniques in data miningKamal Acharya
 
Introduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingIntroduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingKamal Acharya
 

Mehr von Kamal Acharya (20)

Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
 
Computer Arithmetic
Computer ArithmeticComputer Arithmetic
Computer Arithmetic
 
Introduction to Computer Security
Introduction to Computer SecurityIntroduction to Computer Security
Introduction to Computer Security
 
Session and Cookies
Session and CookiesSession and Cookies
Session and Cookies
 
Functions in php
Functions in phpFunctions in php
Functions in php
 
Web forms in php
Web forms in phpWeb forms in php
Web forms in php
 
Making decision and repeating in PHP
Making decision and repeating  in PHPMaking decision and repeating  in PHP
Making decision and repeating in PHP
 
Working with arrays in php
Working with arrays in phpWorking with arrays in php
Working with arrays in php
 
Text and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHPText and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHP
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Capacity Planning of Data Warehousing
Capacity Planning of Data WarehousingCapacity Planning of Data Warehousing
Capacity Planning of Data Warehousing
 
Data Warehousing
Data WarehousingData Warehousing
Data Warehousing
 
Search Engines
Search EnginesSearch Engines
Search Engines
 
Web Mining
Web MiningWeb Mining
Web Mining
 
Information Privacy and Data Mining
Information Privacy and Data MiningInformation Privacy and Data Mining
Information Privacy and Data Mining
 
Cluster Analysis
Cluster AnalysisCluster Analysis
Cluster Analysis
 
Association Analysis in Data Mining
Association Analysis in Data MiningAssociation Analysis in Data Mining
Association Analysis in Data Mining
 
Classification techniques in data mining
Classification techniques in data miningClassification techniques in data mining
Classification techniques in data mining
 
Data Preprocessing
Data PreprocessingData Preprocessing
Data Preprocessing
 
Introduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingIntroduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data Warehousing
 

Kürzlich hochgeladen

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 

Kürzlich hochgeladen (20)

How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 

Functions in C

  • 1. INTRODUCTION TO FUNCTIONS TYPES OF FUNCTIONS ELEMENTS OF USER DEFINED FUNCTIONS TYPES ON THE BASIS OF ARGUMENTS AND RETURN VALUES METHODS OF CALLING A FUNCTION Functions
  • 2. Introduction to Function Block of statements that perform the particular task. Enables modular programming. Main() is the driver function. Has pre defined prototype. Same function can be accessed from different places within a program. Once a function execution is completed , control return to the place from where the function was called.
  • 3. Advantages Modular Programming Length of source program can be reduced Easy to locate and isolate faulty function Functions can be used by other program’s
  • 4. Types of Functions Library (Built In) Functions:  They are written in the header files.  To use them appropriate header files should be included. Header Files Functions Defined stdio.h Printf(), scanf(), getchar(), putchar(), gets(), puts(), fopen(), fclose() conio.h Clrscr(), getch() Ctype.h Toupper(), tolower(), isalpha() Math.h Pow(), sqrt(), cos(), log() Stdlib.h Rand(), exit() String.h Strlen(), strcpy(), strupr()
  • 5. User Defined Functions  Written by the user at the time of programming.
  • 6. Elements of User defined functions Function Prototype Function Call Function arguments and parameters Function Definitions
  • 7. Function prototype It specify the type of value that is to be return from the function and that is to be passed to the function. It is defined in the beginning before the function call is made. Syntax:  return-type name-of-function(list of arguments);  Example Void sum(int, int);
  • 8. Function Call A function can be called by specifying name and list of arguments enclosed in parenthesis and separated by comma. If there is no arguments empty parenthesis are place after function name. If function return a value, function call is written as assignment statement as:  A=sum(x,y);
  • 9. Function arguments and parameters Arguments are also called actual parameters. Arguments are written within parenthesis at the time of function call. Parameters are also called formal parameters. These are written within parenthesis at the time of function definition.
  • 10. Function Definition It is the independent program module. It is written to specify the particular task that is to be performed by the function. The first line of the function is called function declarator and rest line inside { } is called function body
  • 11.
  • 12. Return statement It is the last statement of the function that return certain values. It return certain types of values to the place from where the function was invoked. Syntax:  return(variable-name or constant);
  • 13. Categories of function Function with no arguments and no return Function with arguments but no return Function with no arguments and return Function with arguments and return
  • 14. Function with no argument and no return
  • 15. Function with argument and no return
  • 16. Function with no argument and return
  • 18. Methods of calling function Call by value Call by reference
  • 19. Call by value Copies the value of actual parameters into formal parameters. During execution whatever changes are made in the formal parameters are not reflected back in the actual parameters.
  • 20.
  • 21. Call by Reference Reference(address) of the original variable is passed. Function does not create its own copy, it refers to the original values by reference. Functions works with the original data and changes are made in the original data.