SlideShare a Scribd company logo
1 of 13
Functions in C language
Functions
• A function is a group of statements that together
perform a task.
• Functions are sets of statements that take inputs,
perform some operations, and produce results
 Functions are used to perform certain actions, and
they are important for reusing code:
 Define the code once, and use it many times.
Mehak Bhatia, IIMT College of Science
and Technology
Functions
 Within a function, there are a number of
programming statements enclosed by {}, having
certain meanings and performing certain
operations.
 The operation of a function occurs only when it
is called.
 Rather than writing the same code for different
inputs repeatedly, we can call the function
instead of writing the same code over and over
again.
Mehak Bhatia, IIMT College of Science
and Technology
Creating a Function
Syntax:
void function_name()
{
// code to be executed
}
Example:
void myFunction()
{
printf("Hello World!");
}
Mehak Bhatia, IIMT College of Science
and Technology
Explanation of Example
 myFunction() is the name of the function.
 Inside the function (the body), we have to add
the code that defines what the function should
do.
 void means that the function does not have a
return value.
Mehak Bhatia, IIMT College of Science
and Technology
Why use Functions?
 The function can reduce the repetition of the
same statements in the program.
 The function makes code readable.
 There is no fixed number of calling functions it
can be called as many times as you want.
 The function reduces the size of the program.
 Once the function is declared you can just use it
without thinking about the internal working of
the function.
Mehak Bhatia, IIMT College of Science
and Technology
Syntax of Functions
Mehak Bhatia, IIMT College of Science
and Technology
Defining a Function
The general form of a function definition in
programming language is as follows :
return_type function_name( parameter list )
{
body of the function
}
A function definition in C programming consists of
a function header and a function body.
Mehak Bhatia, IIMT College of Science
and Technology
Here are all the parts of a function −
Mehak Bhatia, IIMT College of Science
and Technology
 Return Type − A function may return a value.
The return_type is the data type of the value
the function returns. Some functions perform
the desired operations without returning a value.
In this case, the return_type is the
keyword void.
 Function Name − This is the actual name of
the function. The function name and the
parameter list together constitute the function
signature.
 Parameters − A parameter is like a placeholder.
When a function is invoked, you pass a value to the
parameter.
 This value is referred to as actual parameter or
argument.
 The parameter list refers to the type, order, and
number of the parameters of a function.
 NOTE: Parameters are optional; that is, a function
may contain no parameters.
 Function Body − The function body contains a
collection of statements that define what the
function does.
Mehak Bhatia, IIMT College of Science
and Technology
Mehak Bhatia, IIMT College of Science
and Technology
Given below is the source code for a function called max().This
function takes two parameters num1 and num2 and returns the
maximum value between the two −
int max(int num1, int num2)
{
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
} Mehak Bhatia, IIMT College of Science
and Technology
THANK YOU
Mehak Bhatia, IIMT College of Science
and Technology

More Related Content

Similar to functions.pptx

Functions in c language
Functions in c languageFunctions in c language
Functions in c languageTanmay Modi
 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 
function of C.pptx
function of C.pptxfunction of C.pptx
function of C.pptxshivas379526
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptxRhishav Poudyal
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functionsnikshaikh786
 
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
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxvekariyakashyap
 
Modular Programming in C
Modular Programming in CModular Programming in C
Modular Programming in Cbhawna kol
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programmingnmahi96
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptxmiki304759
 
unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfJAVVAJI VENKATA RAO
 
Functions in c
Functions in cFunctions in c
Functions in creshmy12
 

Similar to functions.pptx (20)

Functions in c language
Functions in c languageFunctions in c language
Functions in c language
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Function
FunctionFunction
Function
 
function of C.pptx
function of C.pptxfunction of C.pptx
function of C.pptx
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-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
 
Functions
FunctionsFunctions
Functions
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Chapter 1.ppt
Chapter 1.pptChapter 1.ppt
Chapter 1.ppt
 
Modular Programming in C
Modular Programming in CModular Programming in C
Modular Programming in C
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
 
functions new.pptx
functions new.pptxfunctions new.pptx
functions new.pptx
 
C FUNCTIONS
C FUNCTIONSC FUNCTIONS
C FUNCTIONS
 
unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdf
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Functions
Functions Functions
Functions
 

Recently uploaded

TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....rightmanforbloodline
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseWSO2
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformWSO2
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaWSO2
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...caitlingebhard1
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringWSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 

Recently uploaded (20)

TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

functions.pptx

  • 1. Functions in C language
  • 2. Functions • A function is a group of statements that together perform a task. • Functions are sets of statements that take inputs, perform some operations, and produce results  Functions are used to perform certain actions, and they are important for reusing code:  Define the code once, and use it many times. Mehak Bhatia, IIMT College of Science and Technology
  • 3. Functions  Within a function, there are a number of programming statements enclosed by {}, having certain meanings and performing certain operations.  The operation of a function occurs only when it is called.  Rather than writing the same code for different inputs repeatedly, we can call the function instead of writing the same code over and over again. Mehak Bhatia, IIMT College of Science and Technology
  • 4. Creating a Function Syntax: void function_name() { // code to be executed } Example: void myFunction() { printf("Hello World!"); } Mehak Bhatia, IIMT College of Science and Technology
  • 5. Explanation of Example  myFunction() is the name of the function.  Inside the function (the body), we have to add the code that defines what the function should do.  void means that the function does not have a return value. Mehak Bhatia, IIMT College of Science and Technology
  • 6. Why use Functions?  The function can reduce the repetition of the same statements in the program.  The function makes code readable.  There is no fixed number of calling functions it can be called as many times as you want.  The function reduces the size of the program.  Once the function is declared you can just use it without thinking about the internal working of the function. Mehak Bhatia, IIMT College of Science and Technology
  • 7. Syntax of Functions Mehak Bhatia, IIMT College of Science and Technology
  • 8. Defining a Function The general form of a function definition in programming language is as follows : return_type function_name( parameter list ) { body of the function } A function definition in C programming consists of a function header and a function body. Mehak Bhatia, IIMT College of Science and Technology
  • 9. Here are all the parts of a function − Mehak Bhatia, IIMT College of Science and Technology  Return Type − A function may return a value. The return_type is the data type of the value the function returns. Some functions perform the desired operations without returning a value. In this case, the return_type is the keyword void.  Function Name − This is the actual name of the function. The function name and the parameter list together constitute the function signature.
  • 10.  Parameters − A parameter is like a placeholder. When a function is invoked, you pass a value to the parameter.  This value is referred to as actual parameter or argument.  The parameter list refers to the type, order, and number of the parameters of a function.  NOTE: Parameters are optional; that is, a function may contain no parameters.  Function Body − The function body contains a collection of statements that define what the function does. Mehak Bhatia, IIMT College of Science and Technology
  • 11. Mehak Bhatia, IIMT College of Science and Technology
  • 12. Given below is the source code for a function called max().This function takes two parameters num1 and num2 and returns the maximum value between the two − int max(int num1, int num2) { int result; if (num1 > num2) result = num1; else result = num2; return result; } Mehak Bhatia, IIMT College of Science and Technology
  • 13. THANK YOU Mehak Bhatia, IIMT College of Science and Technology