SlideShare a Scribd company logo
RITHIKA. R. S,
I M.Sc. Bioinformatics,
Sri Krishna Arts and Science College, Coimbatore
Introduction…
 A function is a group of statements that together perform a
task.
 It can be executed from as many different parts in a program
as required, it can also return a value to calling program.
 A C program consists of one or more functions.
 Function is a subprogram that helps to reduce the
complexity of a program
Example…
int add (int x, int y)
{
int z;
z=x+y;
return z;
}
Why functions?
 Writing functions avoids rewriting the same code
over and over.
 Using function it becomes easier to write a program
and keep track of what they are doing.
Types of function in C…
Library functions
 Functions such as printf(), scanf() and sqrt() are present in c
library and they are predefined functions.
User defined functions
 A user can create their own functions for performing any specific
task of program. This is said to be user defined functions.
Function definition
 Function definition is also known as function implementation
and includes the following elements:
 Function name
 Function type (return type)
 List of parameters
 Local variable declaration
 Function statements and
 A return statement
return_type function_name (parameter list )
{
local variable declaration;
executable statement1;
executable statement2;
…..
…..
return statement;
}
The general format of a function definition is:
Function definition elements…
 Function header: This consists of 3 parts namely; Function type,
Function name, Parameter list
 The function_type specifies the type of value that the function is
expected to return the program calling the function (such as int,
float, double).
 If function is not returning anything, then specify the return type
as void
 The function_name is any valid C identifier.
 The name should be appropriate to the task performed by the
function, such as sum, add, mul.
 Parameter list declares the variables that will receive the data.
 Parameters are also known as arguments.
 The parameters of the function are enclosed in the parenthesis,
the variables are separated by commas.
 There must be no semicolon after closing the parenthesis
Function declaration…
 Function declaration (function prototype) is declaring the
properties of a function.
 Consists of 4 parts
 Function type(return type)
 Function name
 Parameter list
 Terminating semicolon(;)
 The general format is:
function_type function_name(parameter list);
 For example, mul function can be declared as
int mul (int m, int n); /*function prototype*/
 Various acceptable forms for mul functions are:
 int mul (int, int);
 mul (int a, int b);
 mul (int, int);
 When no parameters and no return value, its prototype is
given as void display(void)
Prototype declaration…
 Function Prototype Declaration is a statement in which
programmer describes three information about a function:
 Symbol name of the function
 Return type of the function
 Arguments that will be taken as input
 A prototype declaration can be in 2 places in program
 (1)above all the functions and
 (2)inside a function definition.
 When a declaration is placed above all the functions, it is
referred to as global prototype.
 When a declaration is place in a function definition, it is
referred a local prototype
The return statement…
 A function may send a value back to the calling function
through the return statement.
 The called function can return only one value per call.
 The return statement can be written in any one of the forms
given
• return; or
• return (expression);
 The first form of plain return does not return any value. An example is
if (error)
return;
 The second form of return with expression returns a value. For example,
int mul (int x, int y)
{
int p;
p=x*y;
return(p);
}
This function returns the value of p, the product of x and y. the last 2
statements cane be combined as
return(x*y);
 A function may have more than one return statements.
if(x<=0)
return(0);
else
return(1);
 All functions return int type data by default. We can make a function to
return particular type of data by using type specifier in the function header.
 Functions that do computations using doubles or float, yet returns ints.
int product (void)
{
return(2.5*3.0)
}
will return the value 7, only integer part.
FUNCTIONS IN C PROGRAMMING.pdf

More Related Content

What's hot

Inline function
Inline functionInline function
Inline functionTech_MX
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
Sivakumar R D .
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
Anil Pokhrel
 
structure and union
structure and unionstructure and union
structure and unionstudent
 
Union in c language
Union  in c languageUnion  in c language
Union in c language
tanmaymodi4
 
Functions In C
Functions In CFunctions In C
Functions In C
Simplilearn
 
Inline functions
Inline functionsInline functions
Inline functions
DhwaniHingorani
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
03062679929
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)
VC Infotech
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
Shakti Singh Rathore
 
Functions in C
Functions in CFunctions in C
Functions in C
Kamal Acharya
 
Function
FunctionFunction
Function
yash patel
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
Vraj Patel
 
Function in c program
Function in c programFunction in c program
Function in c program
umesh patil
 
Recursion in c
Recursion in cRecursion in c
Recursion in c
Saket Pathak
 
Function in C Language
Function in C Language Function in C Language
Function in C Language
programmings guru
 
User defined functions
User defined functionsUser defined functions
User defined functions
Rokonuzzaman Rony
 
Pointer to function 1
Pointer to function 1Pointer to function 1
Pointer to function 1
Abu Bakr Ramadan
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 

What's hot (20)

Inline function
Inline functionInline function
Inline function
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
structure and union
structure and unionstructure and union
structure and union
 
Union in c language
Union  in c languageUnion  in c language
Union in c language
 
Functions In C
Functions In CFunctions In C
Functions In C
 
Inline functions
Inline functionsInline functions
Inline functions
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Function
FunctionFunction
Function
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Recursion in c
Recursion in cRecursion in c
Recursion in c
 
Function in C Language
Function in C Language Function in C Language
Function in C Language
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
Pointer to function 1
Pointer to function 1Pointer to function 1
Pointer to function 1
 
Strings in C
Strings in CStrings in C
Strings in C
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 

Similar to FUNCTIONS IN C PROGRAMMING.pdf

Functions in c
Functions in cFunctions in c
Functions in c
kalavathisugan
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
Md. Imran Hossain Showrov
 
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
 
Functions
FunctionsFunctions
Functions
Pragnavi Erva
 
C functions list
C functions listC functions list
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
Mehul Desai
 
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
Jeevan Raj
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functions
nikshaikh786
 
Dti2143 chapter 5
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5alish sha
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
nmahi96
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
SangeetaBorde3
 
unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdf
JAVVAJI VENKATA RAO
 
Functions
Functions Functions
Functions
Dr.Subha Krishna
 
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++
Muhammad Hammad Waseem
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
kavitha muneeshwaran
 
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
SowmyaJyothi3
 
Amit user defined functions xi (2)
Amit  user defined functions xi (2)Amit  user defined functions xi (2)
Amit user defined functions xi (2)
Arpit Meena
 
4. function
4. function4. function
4. function
Shankar Gangaju
 

Similar to FUNCTIONS IN C PROGRAMMING.pdf (20)

Functions in c
Functions in cFunctions in c
Functions in c
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
 
Functions
FunctionsFunctions
Functions
 
C functions list
C functions listC functions list
C functions list
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
 
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
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functions
 
Dti2143 chapter 5
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
 
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
 
unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdf
 
Functions
Functions Functions
Functions
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++[ITP - Lecture 12] Functions in C/C++
[ITP - Lecture 12] Functions in C/C++
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
 
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
 
Amit user defined functions xi (2)
Amit  user defined functions xi (2)Amit  user defined functions xi (2)
Amit user defined functions xi (2)
 
4. function
4. function4. function
4. function
 

More from RITHIKA R S

Current-good-manufacturing-practices.pdf
Current-good-manufacturing-practices.pdfCurrent-good-manufacturing-practices.pdf
Current-good-manufacturing-practices.pdf
RITHIKA R S
 
Protozoal & ricketsia vaccines.pdf
Protozoal & ricketsia vaccines.pdfProtozoal & ricketsia vaccines.pdf
Protozoal & ricketsia vaccines.pdf
RITHIKA R S
 
Down syndrome.pdf
Down syndrome.pdfDown syndrome.pdf
Down syndrome.pdf
RITHIKA R S
 
EVALUATION OF DRUG EFFECTS.pdf
EVALUATION OF DRUG EFFECTS.pdfEVALUATION OF DRUG EFFECTS.pdf
EVALUATION OF DRUG EFFECTS.pdf
RITHIKA R S
 
DNAfingerprinting poster.pdf
DNAfingerprinting poster.pdfDNAfingerprinting poster.pdf
DNAfingerprinting poster.pdf
RITHIKA R S
 
Conditional-probability-and-Bioinformatics.pptx
Conditional-probability-and-Bioinformatics.pptxConditional-probability-and-Bioinformatics.pptx
Conditional-probability-and-Bioinformatics.pptx
RITHIKA R S
 
THIRD GEN SEQUENCING.pptx
THIRD GEN SEQUENCING.pptxTHIRD GEN SEQUENCING.pptx
THIRD GEN SEQUENCING.pptx
RITHIKA R S
 
LAC OPERON.pdf
LAC OPERON.pdfLAC OPERON.pdf
LAC OPERON.pdf
RITHIKA R S
 
CRISPR_cas9_tech.pptx
CRISPR_cas9_tech.pptxCRISPR_cas9_tech.pptx
CRISPR_cas9_tech.pptx
RITHIKA R S
 

More from RITHIKA R S (9)

Current-good-manufacturing-practices.pdf
Current-good-manufacturing-practices.pdfCurrent-good-manufacturing-practices.pdf
Current-good-manufacturing-practices.pdf
 
Protozoal & ricketsia vaccines.pdf
Protozoal & ricketsia vaccines.pdfProtozoal & ricketsia vaccines.pdf
Protozoal & ricketsia vaccines.pdf
 
Down syndrome.pdf
Down syndrome.pdfDown syndrome.pdf
Down syndrome.pdf
 
EVALUATION OF DRUG EFFECTS.pdf
EVALUATION OF DRUG EFFECTS.pdfEVALUATION OF DRUG EFFECTS.pdf
EVALUATION OF DRUG EFFECTS.pdf
 
DNAfingerprinting poster.pdf
DNAfingerprinting poster.pdfDNAfingerprinting poster.pdf
DNAfingerprinting poster.pdf
 
Conditional-probability-and-Bioinformatics.pptx
Conditional-probability-and-Bioinformatics.pptxConditional-probability-and-Bioinformatics.pptx
Conditional-probability-and-Bioinformatics.pptx
 
THIRD GEN SEQUENCING.pptx
THIRD GEN SEQUENCING.pptxTHIRD GEN SEQUENCING.pptx
THIRD GEN SEQUENCING.pptx
 
LAC OPERON.pdf
LAC OPERON.pdfLAC OPERON.pdf
LAC OPERON.pdf
 
CRISPR_cas9_tech.pptx
CRISPR_cas9_tech.pptxCRISPR_cas9_tech.pptx
CRISPR_cas9_tech.pptx
 

Recently uploaded

Lab report on liquid viscosity of glycerin
Lab report on liquid viscosity of glycerinLab report on liquid viscosity of glycerin
Lab report on liquid viscosity of glycerin
ossaicprecious19
 
Body fluids_tonicity_dehydration_hypovolemia_hypervolemia.pptx
Body fluids_tonicity_dehydration_hypovolemia_hypervolemia.pptxBody fluids_tonicity_dehydration_hypovolemia_hypervolemia.pptx
Body fluids_tonicity_dehydration_hypovolemia_hypervolemia.pptx
muralinath2
 
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Sérgio Sacani
 
Orion Air Quality Monitoring Systems - CWS
Orion Air Quality Monitoring Systems - CWSOrion Air Quality Monitoring Systems - CWS
Orion Air Quality Monitoring Systems - CWS
Columbia Weather Systems
 
Hemostasis_importance& clinical significance.pptx
Hemostasis_importance& clinical significance.pptxHemostasis_importance& clinical significance.pptx
Hemostasis_importance& clinical significance.pptx
muralinath2
 
general properties of oerganologametal.ppt
general properties of oerganologametal.pptgeneral properties of oerganologametal.ppt
general properties of oerganologametal.ppt
IqrimaNabilatulhusni
 
insect taxonomy importance systematics and classification
insect taxonomy importance systematics and classificationinsect taxonomy importance systematics and classification
insect taxonomy importance systematics and classification
anitaento25
 
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
NathanBaughman3
 
GBSN- Microbiology (Lab 3) Gram Staining
GBSN- Microbiology (Lab 3) Gram StainingGBSN- Microbiology (Lab 3) Gram Staining
GBSN- Microbiology (Lab 3) Gram Staining
Areesha Ahmad
 
Citrus Greening Disease and its Management
Citrus Greening Disease and its ManagementCitrus Greening Disease and its Management
Citrus Greening Disease and its Management
subedisuryaofficial
 
Comparative structure of adrenal gland in vertebrates
Comparative structure of adrenal gland in vertebratesComparative structure of adrenal gland in vertebrates
Comparative structure of adrenal gland in vertebrates
sachin783648
 
Mammalian Pineal Body Structure and Also Functions
Mammalian Pineal Body Structure and Also FunctionsMammalian Pineal Body Structure and Also Functions
Mammalian Pineal Body Structure and Also Functions
YOGESH DOGRA
 
platelets- lifespan -Clot retraction-disorders.pptx
platelets- lifespan -Clot retraction-disorders.pptxplatelets- lifespan -Clot retraction-disorders.pptx
platelets- lifespan -Clot retraction-disorders.pptx
muralinath2
 
Nutraceutical market, scope and growth: Herbal drug technology
Nutraceutical market, scope and growth: Herbal drug technologyNutraceutical market, scope and growth: Herbal drug technology
Nutraceutical market, scope and growth: Herbal drug technology
Lokesh Patil
 
RNA INTERFERENCE: UNRAVELING GENETIC SILENCING
RNA INTERFERENCE: UNRAVELING GENETIC SILENCINGRNA INTERFERENCE: UNRAVELING GENETIC SILENCING
RNA INTERFERENCE: UNRAVELING GENETIC SILENCING
AADYARAJPANDEY1
 
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
Sérgio Sacani
 
Seminar of U.V. Spectroscopy by SAMIR PANDA
 Seminar of U.V. Spectroscopy by SAMIR PANDA Seminar of U.V. Spectroscopy by SAMIR PANDA
Seminar of U.V. Spectroscopy by SAMIR PANDA
SAMIR PANDA
 
GBSN - Biochemistry (Unit 5) Chemistry of Lipids
GBSN - Biochemistry (Unit 5) Chemistry of LipidsGBSN - Biochemistry (Unit 5) Chemistry of Lipids
GBSN - Biochemistry (Unit 5) Chemistry of Lipids
Areesha Ahmad
 
Lateral Ventricles.pdf very easy good diagrams comprehensive
Lateral Ventricles.pdf very easy good diagrams comprehensiveLateral Ventricles.pdf very easy good diagrams comprehensive
Lateral Ventricles.pdf very easy good diagrams comprehensive
silvermistyshot
 
erythropoiesis-I_mechanism& clinical significance.pptx
erythropoiesis-I_mechanism& clinical significance.pptxerythropoiesis-I_mechanism& clinical significance.pptx
erythropoiesis-I_mechanism& clinical significance.pptx
muralinath2
 

Recently uploaded (20)

Lab report on liquid viscosity of glycerin
Lab report on liquid viscosity of glycerinLab report on liquid viscosity of glycerin
Lab report on liquid viscosity of glycerin
 
Body fluids_tonicity_dehydration_hypovolemia_hypervolemia.pptx
Body fluids_tonicity_dehydration_hypovolemia_hypervolemia.pptxBody fluids_tonicity_dehydration_hypovolemia_hypervolemia.pptx
Body fluids_tonicity_dehydration_hypovolemia_hypervolemia.pptx
 
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
Observation of Io’s Resurfacing via Plume Deposition Using Ground-based Adapt...
 
Orion Air Quality Monitoring Systems - CWS
Orion Air Quality Monitoring Systems - CWSOrion Air Quality Monitoring Systems - CWS
Orion Air Quality Monitoring Systems - CWS
 
Hemostasis_importance& clinical significance.pptx
Hemostasis_importance& clinical significance.pptxHemostasis_importance& clinical significance.pptx
Hemostasis_importance& clinical significance.pptx
 
general properties of oerganologametal.ppt
general properties of oerganologametal.pptgeneral properties of oerganologametal.ppt
general properties of oerganologametal.ppt
 
insect taxonomy importance systematics and classification
insect taxonomy importance systematics and classificationinsect taxonomy importance systematics and classification
insect taxonomy importance systematics and classification
 
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
Astronomy Update- Curiosity’s exploration of Mars _ Local Briefs _ leadertele...
 
GBSN- Microbiology (Lab 3) Gram Staining
GBSN- Microbiology (Lab 3) Gram StainingGBSN- Microbiology (Lab 3) Gram Staining
GBSN- Microbiology (Lab 3) Gram Staining
 
Citrus Greening Disease and its Management
Citrus Greening Disease and its ManagementCitrus Greening Disease and its Management
Citrus Greening Disease and its Management
 
Comparative structure of adrenal gland in vertebrates
Comparative structure of adrenal gland in vertebratesComparative structure of adrenal gland in vertebrates
Comparative structure of adrenal gland in vertebrates
 
Mammalian Pineal Body Structure and Also Functions
Mammalian Pineal Body Structure and Also FunctionsMammalian Pineal Body Structure and Also Functions
Mammalian Pineal Body Structure and Also Functions
 
platelets- lifespan -Clot retraction-disorders.pptx
platelets- lifespan -Clot retraction-disorders.pptxplatelets- lifespan -Clot retraction-disorders.pptx
platelets- lifespan -Clot retraction-disorders.pptx
 
Nutraceutical market, scope and growth: Herbal drug technology
Nutraceutical market, scope and growth: Herbal drug technologyNutraceutical market, scope and growth: Herbal drug technology
Nutraceutical market, scope and growth: Herbal drug technology
 
RNA INTERFERENCE: UNRAVELING GENETIC SILENCING
RNA INTERFERENCE: UNRAVELING GENETIC SILENCINGRNA INTERFERENCE: UNRAVELING GENETIC SILENCING
RNA INTERFERENCE: UNRAVELING GENETIC SILENCING
 
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
THE IMPORTANCE OF MARTIAN ATMOSPHERE SAMPLE RETURN.
 
Seminar of U.V. Spectroscopy by SAMIR PANDA
 Seminar of U.V. Spectroscopy by SAMIR PANDA Seminar of U.V. Spectroscopy by SAMIR PANDA
Seminar of U.V. Spectroscopy by SAMIR PANDA
 
GBSN - Biochemistry (Unit 5) Chemistry of Lipids
GBSN - Biochemistry (Unit 5) Chemistry of LipidsGBSN - Biochemistry (Unit 5) Chemistry of Lipids
GBSN - Biochemistry (Unit 5) Chemistry of Lipids
 
Lateral Ventricles.pdf very easy good diagrams comprehensive
Lateral Ventricles.pdf very easy good diagrams comprehensiveLateral Ventricles.pdf very easy good diagrams comprehensive
Lateral Ventricles.pdf very easy good diagrams comprehensive
 
erythropoiesis-I_mechanism& clinical significance.pptx
erythropoiesis-I_mechanism& clinical significance.pptxerythropoiesis-I_mechanism& clinical significance.pptx
erythropoiesis-I_mechanism& clinical significance.pptx
 

FUNCTIONS IN C PROGRAMMING.pdf

  • 1. RITHIKA. R. S, I M.Sc. Bioinformatics, Sri Krishna Arts and Science College, Coimbatore
  • 2. Introduction…  A function is a group of statements that together perform a task.  It can be executed from as many different parts in a program as required, it can also return a value to calling program.  A C program consists of one or more functions.  Function is a subprogram that helps to reduce the complexity of a program
  • 3. Example… int add (int x, int y) { int z; z=x+y; return z; }
  • 4. Why functions?  Writing functions avoids rewriting the same code over and over.  Using function it becomes easier to write a program and keep track of what they are doing.
  • 5. Types of function in C… Library functions  Functions such as printf(), scanf() and sqrt() are present in c library and they are predefined functions. User defined functions  A user can create their own functions for performing any specific task of program. This is said to be user defined functions.
  • 6. Function definition  Function definition is also known as function implementation and includes the following elements:  Function name  Function type (return type)  List of parameters  Local variable declaration  Function statements and  A return statement
  • 7. return_type function_name (parameter list ) { local variable declaration; executable statement1; executable statement2; ….. ….. return statement; } The general format of a function definition is:
  • 8. Function definition elements…  Function header: This consists of 3 parts namely; Function type, Function name, Parameter list  The function_type specifies the type of value that the function is expected to return the program calling the function (such as int, float, double).  If function is not returning anything, then specify the return type as void
  • 9.  The function_name is any valid C identifier.  The name should be appropriate to the task performed by the function, such as sum, add, mul.  Parameter list declares the variables that will receive the data.  Parameters are also known as arguments.  The parameters of the function are enclosed in the parenthesis, the variables are separated by commas.  There must be no semicolon after closing the parenthesis
  • 10. Function declaration…  Function declaration (function prototype) is declaring the properties of a function.  Consists of 4 parts  Function type(return type)  Function name  Parameter list  Terminating semicolon(;)  The general format is: function_type function_name(parameter list);
  • 11.  For example, mul function can be declared as int mul (int m, int n); /*function prototype*/  Various acceptable forms for mul functions are:  int mul (int, int);  mul (int a, int b);  mul (int, int);  When no parameters and no return value, its prototype is given as void display(void)
  • 12. Prototype declaration…  Function Prototype Declaration is a statement in which programmer describes three information about a function:  Symbol name of the function  Return type of the function  Arguments that will be taken as input  A prototype declaration can be in 2 places in program  (1)above all the functions and  (2)inside a function definition.
  • 13.  When a declaration is placed above all the functions, it is referred to as global prototype.  When a declaration is place in a function definition, it is referred a local prototype
  • 14. The return statement…  A function may send a value back to the calling function through the return statement.  The called function can return only one value per call.  The return statement can be written in any one of the forms given • return; or • return (expression);
  • 15.  The first form of plain return does not return any value. An example is if (error) return;  The second form of return with expression returns a value. For example, int mul (int x, int y) { int p; p=x*y; return(p); } This function returns the value of p, the product of x and y. the last 2 statements cane be combined as return(x*y);
  • 16.  A function may have more than one return statements. if(x<=0) return(0); else return(1);  All functions return int type data by default. We can make a function to return particular type of data by using type specifier in the function header.  Functions that do computations using doubles or float, yet returns ints. int product (void) { return(2.5*3.0) } will return the value 7, only integer part.