SlideShare a Scribd company logo
2
Most read
5
Most read
15
Most read
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

PPT
History of c
PPTX
Straight lines
PPTX
Digital Marketing Overview
PPTX
Hyperbolas
PPT
biostatstics :Type and presentation of data
PPSX
Function in c
PPTX
Diabetes Mellitus
PPTX
Hypertension
History of c
Straight lines
Digital Marketing Overview
Hyperbolas
biostatstics :Type and presentation of data
Function in c
Diabetes Mellitus
Hypertension

What's hot (20)

PPT
Function overloading(c++)
PPTX
Call by value
PPTX
Operators and expressions in c language
PPTX
Stack Operations
PPTX
Functions in C
PPT
Variables in C Programming
PPTX
Pointers in C Programming
PPTX
Function in C program
PPTX
data types in C programming
PPTX
Functions in c++
PPSX
Type conversion
PPT
How to execute a C program
PDF
Introduction to c++ ppt 1
PPTX
Destructors
PDF
C Pointers
PPTX
Pointers in C Language
PPTX
C programming - String
PPTX
Type casting in c programming
PPTX
Functions in c language
PPTX
Increment and Decrement operators in C++
Function overloading(c++)
Call by value
Operators and expressions in c language
Stack Operations
Functions in C
Variables in C Programming
Pointers in C Programming
Function in C program
data types in C programming
Functions in c++
Type conversion
How to execute a C program
Introduction to c++ ppt 1
Destructors
C Pointers
Pointers in C Language
C programming - String
Type casting in c programming
Functions in c language
Increment and Decrement operators in C++
Ad

Similar to FUNCTIONS IN C PROGRAMMING.pdf (20)

PPTX
Functions in c
PPT
Lecture 11 - Functions
PPTX
User defined function in C.pptx
PDF
Functions
PPTX
Unit-III.pptx
DOCX
C programming language working with functions 1
PPTX
Module 3-Functions
PPTX
Detailed concept of function in c programming
PPTX
Dti2143 chapter 5
PPTX
Lecture_5_-_Functions_in_C_Detailed.pptx
PDF
Functions-Computer programming
PPTX
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
PDF
unit3 part2 pcds function notes.pdf
DOC
Functions
PPT
Ch4 functions
PPTX
Function C programming
PDF
[ITP - Lecture 12] Functions in C/C++
PPTX
C and C++ functions
PDF
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
Functions in c
Lecture 11 - Functions
User defined function in C.pptx
Functions
Unit-III.pptx
C programming language working with functions 1
Module 3-Functions
Detailed concept of function in c programming
Dti2143 chapter 5
Lecture_5_-_Functions_in_C_Detailed.pptx
Functions-Computer programming
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
unit3 part2 pcds function notes.pdf
Functions
Ch4 functions
Function C programming
[ITP - Lecture 12] Functions in C/C++
C and C++ functions
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
Ad

More from RITHIKA R S (9)

PDF
Current-good-manufacturing-practices.pdf
PDF
Protozoal & ricketsia vaccines.pdf
PDF
Down syndrome.pdf
PDF
EVALUATION OF DRUG EFFECTS.pdf
PDF
DNAfingerprinting poster.pdf
PPTX
Conditional-probability-and-Bioinformatics.pptx
PPTX
THIRD GEN SEQUENCING.pptx
PDF
LAC OPERON.pdf
PPTX
CRISPR_cas9_tech.pptx
Current-good-manufacturing-practices.pdf
Protozoal & ricketsia vaccines.pdf
Down syndrome.pdf
EVALUATION OF DRUG EFFECTS.pdf
DNAfingerprinting poster.pdf
Conditional-probability-and-Bioinformatics.pptx
THIRD GEN SEQUENCING.pptx
LAC OPERON.pdf
CRISPR_cas9_tech.pptx

Recently uploaded (20)

PDF
VARICELLA VACCINATION: A POTENTIAL STRATEGY FOR PREVENTING MULTIPLE SCLEROSIS
PDF
Phytochemical Investigation of Miliusa longipes.pdf
PPTX
The KM-GBF monitoring framework – status & key messages.pptx
PDF
IFIT3 RNA-binding activity primores influenza A viruz infection and translati...
PPT
The World of Physical Science, • Labs: Safety Simulation, Measurement Practice
PPTX
microscope-Lecturecjchchchchcuvuvhc.pptx
PPTX
Protein & Amino Acid Structures Levels of protein structure (primary, seconda...
PPTX
Cell Membrane: Structure, Composition & Functions
PPTX
2. Earth - The Living Planet Module 2ELS
PPTX
ANEMIA WITH LEUKOPENIA MDS 07_25.pptx htggtftgt fredrctvg
PDF
AlphaEarth Foundations and the Satellite Embedding dataset
PDF
Mastering Bioreactors and Media Sterilization: A Complete Guide to Sterile Fe...
PPTX
G5Q1W8 PPT SCIENCE.pptx 2025-2026 GRADE 5
PDF
Sciences of Europe No 170 (2025)
PPTX
BIOMOLECULES PPT........................
PPTX
cpcsea ppt.pptxssssssssssssssjjdjdndndddd
PDF
Unveiling a 36 billion solar mass black hole at the centre of the Cosmic Hors...
PDF
CAPERS-LRD-z9:AGas-enshroudedLittleRedDotHostingaBroad-lineActive GalacticNuc...
PDF
Biophysics 2.pdffffffffffffffffffffffffff
PPTX
Taita Taveta Laboratory Technician Workshop Presentation.pptx
VARICELLA VACCINATION: A POTENTIAL STRATEGY FOR PREVENTING MULTIPLE SCLEROSIS
Phytochemical Investigation of Miliusa longipes.pdf
The KM-GBF monitoring framework – status & key messages.pptx
IFIT3 RNA-binding activity primores influenza A viruz infection and translati...
The World of Physical Science, • Labs: Safety Simulation, Measurement Practice
microscope-Lecturecjchchchchcuvuvhc.pptx
Protein & Amino Acid Structures Levels of protein structure (primary, seconda...
Cell Membrane: Structure, Composition & Functions
2. Earth - The Living Planet Module 2ELS
ANEMIA WITH LEUKOPENIA MDS 07_25.pptx htggtftgt fredrctvg
AlphaEarth Foundations and the Satellite Embedding dataset
Mastering Bioreactors and Media Sterilization: A Complete Guide to Sterile Fe...
G5Q1W8 PPT SCIENCE.pptx 2025-2026 GRADE 5
Sciences of Europe No 170 (2025)
BIOMOLECULES PPT........................
cpcsea ppt.pptxssssssssssssssjjdjdndndddd
Unveiling a 36 billion solar mass black hole at the centre of the Cosmic Hors...
CAPERS-LRD-z9:AGas-enshroudedLittleRedDotHostingaBroad-lineActive GalacticNuc...
Biophysics 2.pdffffffffffffffffffffffffff
Taita Taveta Laboratory Technician Workshop Presentation.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.