SlideShare a Scribd company logo
1 of 24
Marathwada Mitramandal’s
COLLEGE OF ENGINEERING
Karvenagar, Pune
Accredited with ‘A++’ Grade by NAAC
“Functions In C”
By
Mrs. Ashwini Raut
Department of Computer Engineering
Session
Outline
• What is Function
• Advantages of using function
• Types of function
• Function Prototype
• Defining function
• Calling Function
• Return Statement
• Local and global Variables
• Categories Of Function
• Recursion
What is
function
• A function is a group of statements that together
perform a task.
• Every c program has at least one function called
main()
Advantages
of Using
Function
• The use of functions makes a program more readable. It's
frequently difficult to read a large program. Breaking the
code down into smaller functions keeps the program
structured, understandable, and reusable.
• The function can be reused countless times after it is
defined.
• Using a function, it is possible to reduce the size of a
program by calling and using the function at different
places in the program.
• Functions help in code modularity, which means that the
entire code is divided into separate blocks, each of which is
self-contained and performs a different task. This makes
each block implementation and debugging much easier.
Types of
function
Types of
function
1. Build in Function /Library Functions:
• These functions are grouped together and
placed in common folder called library.
• E.g: printf(),scanf()
2.User Defined Functions:
• These functions are created by user
according to programming need are called as
user defined functions.
• E.g: Function to perform addition of two int
numbers
Elements of
User Defined
Functions
1.Function Prototype
2.Function Call
3.Function Arguments and parameters
4.Function Definition
Function
Prototype
• It is defined in the beginning before the
function call is made.
• Syntax:
return_type name_of_function(list_of_arguments);
E.g: int sum(int a ,int b);
Function Call
• Function call can be made by specifying name and
list of arguments enclosed in parenthesis and
separated by comma.
• If there are no arguments empty parenthesis are
placed after function name.
• Syntax:
name_of_function(list_of_arguments);
• If function return a value then function call can be
written as :
c=sum(x,y);
Function
arguments
and
parameters
• Arguments are also called as actual parameters.
• Arguments are written within parenthesis at the time
of function call.
• Parameters are also called as Formal parameters.
• Parameters are written within parenthesis at the time
of function definition.
Function
Definition
• It is dependant on program module.
• We can write actual logic into function definition
• First line of the function is called function declaration
and rest line inside {} are called function body.
Return
statement
• It is the last statement of the function that return
certain value where the function is called.
• Syntax:
return(variable name or constant);
• E.g: return(c);
Local and
Global
Variable
• Local Variable: The variable whose scope lies inside a
function or a block in which they are declared.
• Global Variable: The variable that exists outside of all
functions. It is the variable that is visible from all other
scopes.
Categories
of Function
1.Function with arguments and with return type
#include <stdio.h>
void main()
{
int sub(int,int); //function with return value and arguments
int x=10,y=7;
int res = sub(x,y);
printf("x-y = %d",res);
}
int sub(int a,int b) //function with return value and arguments
{
return(a-b); // return value
}
Categories
of Function
2. Functions with arguments and without return values
#include <stdio.h>
int main()
{
void sum(int,int); //function with arguments and no return value
int x=10,y=7;
sum(x,y);
}
void sum(int a,int b) //function with arguments and no return value
{
int z = a+b;
printf("x + y = %d",z);
}
Categories
of Function
3. Functions without arguments and with return values
#include<stdio.h>
int main()
{
int sum();
int c = sum();
printf("Sum = %d",c);
}
int sum() //function with no arguments and return data type
{
int x=10,y=20,z=5;
printf("x = %d ; y = %d ; z = %d n",x,y,z);
int sum = x+y+z;
return(sum);
}
Categories
of Function
4. Functions without arguments and without return values
#include<stdio.h>
int main()
{
void sum();
sum();
}
void sum() //function with no arguments and return data type
{
int x=15,y=35,z=5;
printf("x = %d ; y = %d ; z = %d n",x,y,z);
int sum = x+y+z;
printf("Sum = %d",sum);
}
Call By Value
• In call by value method of parameter passing, the values
of actual parameters are copied to the function’s formal
parameters.
• There are two copies of parameters stored in different
memory locations.
• One is the original copy and the other is the function
copy.
• Any changes made inside functions are not reflected in
the actual parameters of the caller.
Call By
Reference
• In call by reference method of parameter passing, the
address of the actual parameters is passed to the
function as the formal parameters.
• Both the actual and formal parameters refer to the same
locations.
• Any changes made inside the function are actually
reflected in the actual parameters of the caller.
Recursion in C
Recursion is the technique of
making a function call itself.
#include<stdio.h>
int sum(int k);
int main() {
int result = sum(10);
printf("%d", result);
return 0;
}
int sum(int k) {
if (k > 0) {
return k + sum(k - 1);
} else {
return 0;
}}
Thank You
Any Questions?

More Related Content

Similar to Functions in C.pptx

Similar to Functions in C.pptx (20)

Functions
FunctionsFunctions
Functions
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
c.p function
c.p functionc.p function
c.p function
 
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
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
Functions in C++.pdf
Functions in C++.pdfFunctions in C++.pdf
Functions in C++.pdf
 
Functions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptxFunctions IN CPROGRAMMING OF ENGINEERING.pptx
Functions IN CPROGRAMMING OF ENGINEERING.pptx
 
1.6 Function.pdf
1.6 Function.pdf1.6 Function.pdf
1.6 Function.pdf
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).ppt
 
Functionincprogram
FunctionincprogramFunctionincprogram
Functionincprogram
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
 
C function
C functionC function
C function
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptx
 
Functions
FunctionsFunctions
Functions
 
Function
FunctionFunction
Function
 
Unit iii
Unit iiiUnit iii
Unit iii
 
Functions in c
Functions in cFunctions in c
Functions in c
 
function in in thi pdf you will learn what is fu...
function in  in thi pdf you will learn   what                           is fu...function in  in thi pdf you will learn   what                           is fu...
function in in thi pdf you will learn what is fu...
 
Functions
Functions Functions
Functions
 

Recently uploaded

OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
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
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
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
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
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
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 

Recently uploaded (20)

OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
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
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
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
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
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
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
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
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
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
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 

Functions in C.pptx

  • 1. Marathwada Mitramandal’s COLLEGE OF ENGINEERING Karvenagar, Pune Accredited with ‘A++’ Grade by NAAC “Functions In C” By Mrs. Ashwini Raut Department of Computer Engineering
  • 2. Session Outline • What is Function • Advantages of using function • Types of function • Function Prototype • Defining function • Calling Function • Return Statement • Local and global Variables • Categories Of Function • Recursion
  • 3. What is function • A function is a group of statements that together perform a task. • Every c program has at least one function called main()
  • 4. Advantages of Using Function • The use of functions makes a program more readable. It's frequently difficult to read a large program. Breaking the code down into smaller functions keeps the program structured, understandable, and reusable. • The function can be reused countless times after it is defined. • Using a function, it is possible to reduce the size of a program by calling and using the function at different places in the program. • Functions help in code modularity, which means that the entire code is divided into separate blocks, each of which is self-contained and performs a different task. This makes each block implementation and debugging much easier.
  • 6. Types of function 1. Build in Function /Library Functions: • These functions are grouped together and placed in common folder called library. • E.g: printf(),scanf() 2.User Defined Functions: • These functions are created by user according to programming need are called as user defined functions. • E.g: Function to perform addition of two int numbers
  • 7. Elements of User Defined Functions 1.Function Prototype 2.Function Call 3.Function Arguments and parameters 4.Function Definition
  • 8. Function Prototype • It is defined in the beginning before the function call is made. • Syntax: return_type name_of_function(list_of_arguments); E.g: int sum(int a ,int b);
  • 9. Function Call • Function call can be made by specifying name and list of arguments enclosed in parenthesis and separated by comma. • If there are no arguments empty parenthesis are placed after function name. • Syntax: name_of_function(list_of_arguments); • If function return a value then function call can be written as : c=sum(x,y);
  • 10. Function arguments and parameters • Arguments are also called as actual parameters. • Arguments are written within parenthesis at the time of function call. • Parameters are also called as Formal parameters. • Parameters are written within parenthesis at the time of function definition.
  • 11. Function Definition • It is dependant on program module. • We can write actual logic into function definition • First line of the function is called function declaration and rest line inside {} are called function body.
  • 12. Return statement • It is the last statement of the function that return certain value where the function is called. • Syntax: return(variable name or constant); • E.g: return(c);
  • 13.
  • 14.
  • 15. Local and Global Variable • Local Variable: The variable whose scope lies inside a function or a block in which they are declared. • Global Variable: The variable that exists outside of all functions. It is the variable that is visible from all other scopes.
  • 16.
  • 17. Categories of Function 1.Function with arguments and with return type #include <stdio.h> void main() { int sub(int,int); //function with return value and arguments int x=10,y=7; int res = sub(x,y); printf("x-y = %d",res); } int sub(int a,int b) //function with return value and arguments { return(a-b); // return value }
  • 18. Categories of Function 2. Functions with arguments and without return values #include <stdio.h> int main() { void sum(int,int); //function with arguments and no return value int x=10,y=7; sum(x,y); } void sum(int a,int b) //function with arguments and no return value { int z = a+b; printf("x + y = %d",z); }
  • 19. Categories of Function 3. Functions without arguments and with return values #include<stdio.h> int main() { int sum(); int c = sum(); printf("Sum = %d",c); } int sum() //function with no arguments and return data type { int x=10,y=20,z=5; printf("x = %d ; y = %d ; z = %d n",x,y,z); int sum = x+y+z; return(sum); }
  • 20. Categories of Function 4. Functions without arguments and without return values #include<stdio.h> int main() { void sum(); sum(); } void sum() //function with no arguments and return data type { int x=15,y=35,z=5; printf("x = %d ; y = %d ; z = %d n",x,y,z); int sum = x+y+z; printf("Sum = %d",sum); }
  • 21. Call By Value • In call by value method of parameter passing, the values of actual parameters are copied to the function’s formal parameters. • There are two copies of parameters stored in different memory locations. • One is the original copy and the other is the function copy. • Any changes made inside functions are not reflected in the actual parameters of the caller.
  • 22. Call By Reference • In call by reference method of parameter passing, the address of the actual parameters is passed to the function as the formal parameters. • Both the actual and formal parameters refer to the same locations. • Any changes made inside the function are actually reflected in the actual parameters of the caller.
  • 23. Recursion in C Recursion is the technique of making a function call itself. #include<stdio.h> int sum(int k); int main() { int result = sum(10); printf("%d", result); return 0; } int sum(int k) { if (k > 0) { return k + sum(k - 1); } else { return 0; }}