SlideShare a Scribd company logo
C PROGRAMMING
Functions
By,
Mr. Shekharkumar
What is Function?
• A function is a block of code that performs a specific task.
• A function only runs when it is called.
• You can pass data, known as parameters, into a function.
• Functions are used to perform certain actions, and they are important for
reusing code: Define the code once, and use it many times.
Types of function
• There are two types of function in C programming:
1. Standard library functions (Pre-Defined Functions)
2. User-defined functions
1. Standard library functions (Pre-Defined Functions)
• The standard library functions are built-in functions in C programming.
• These functions are defined in header files. For example,
The printf() is a standard library function to display formatted output to the
screen. This function is defined in the stdio.h header file. Hence to use printf()
function, we need to include the stdio.h header file using #include <stdio.h>.
The sqrt() function calculates the square root of a number. The function is
defined in the math.h header file
2. User-defined functions
• User-defined functions are a block of code written by the user to
perform a specific action. A user-defined function has a return type,
a function name, parameters, and body of the function. Function can
be called using the unique name of the function followed by function
parameters passed inside round brackets ().
Advantages of user-defined function
The program will be easier to understand, maintain and debug.
Reusable codes that can be used in other programs
A large program can be divided into smaller modules. Hence, a large
project can be divided among many programmers.
5. Functions in C.pdf
How function works
• The execution of a C program begins from the main() function
• When the compiler encounters functionname() control of the program jumps
to void functionname()
• And, the compiler starts executing the codes inside functionname().
• The control of the program jumps back to the main() function once
code inside the function definition is executed.
#include <stdio.h>
int addNumbers(int a, int b); // function prototype
int addNumbers(int a, int b) // function definition
{
int result;
result = a+b;
return result; // return statement
}
void main()
{
int n1,n2,sum;
printf("Enters two numbers: ");
scanf("%d %d",&n1,&n2);
sum = addNumbers(n1, n2); // function call
printf("sum = %d",sum);
}
Example of user-defined function

More Related Content

PPTX
Functions and structure in programming c
dalalbhargavi19
 
PPTX
Functions and Header files ver very useful
RamSiddesh1
 
PPTX
Functions
Lakshmi Sarvani Videla
 
PPTX
The function contains the set of programming statements enclosed by {}  when ...
MdAmreen
 
PPTX
Chapter One Function.pptx
miki304759
 
PPTX
Funtions of c programming. the functions of c helps to clarify all the tops
sameermhr345
 
PPTX
Chapter 1 (2) array and structure r.pptx
abenezertekalign118
 
PPTX
DS functions-1.pptx
HarikishnaKNHk
 
Functions and structure in programming c
dalalbhargavi19
 
Functions and Header files ver very useful
RamSiddesh1
 
The function contains the set of programming statements enclosed by {}  when ...
MdAmreen
 
Chapter One Function.pptx
miki304759
 
Funtions of c programming. the functions of c helps to clarify all the tops
sameermhr345
 
Chapter 1 (2) array and structure r.pptx
abenezertekalign118
 
DS functions-1.pptx
HarikishnaKNHk
 

Similar to 5. Functions in C.pdf (20)

PPT
U19CS101 - PPS Unit 4 PPT (1).ppt
Manivannan837728
 
PDF
Programming Fundamentals Functions in C and types
imtiazalijoono
 
PPT
POLITEKNIK MALAYSIA
Aiman Hud
 
PPTX
unit_2 (1).pptx
JVenkateshGoud
 
PPTX
Function oneshot with python programming .pptx
lionsconvent1234
 
PPTX
Function in C Programming
Anil Pokhrel
 
PPTX
unit_2.pptx
Venkatesh Goud
 
PPTX
Lecture_5_-_Functions_in_C_Detailed.pptx
Salim Shadman Ankur
 
PPT
Chapter Introduction to Modular Programming.ppt
AmanuelZewdie4
 
PPT
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
harinipradeep15
 
PPTX
Lecture 1_Functions in C.pptx
KhurramKhan173
 
PPT
arrays.ppt
Bharath904863
 
PPTX
FUNCTIONengineeringtechnologyslidesh.pptx
ricknova674
 
PPTX
FUNCTION.pptxfkrdutytrtttrrtttttttttttttt
hboi8164
 
PPTX
C++ Functions.pptx
DikshaDani5
 
PPT
C FUNCTIONS
TeenaGeorge15
 
PPTX
CH.4FUNCTIONS IN C (1).pptx
sangeeta borde
 
PPTX
C functions by ranjan call by value and reference.pptx
ranjan317165
 
PPTX
About the C program's basic function for beginner students
sabbirahmednomaninfo
 
PPTX
Presentation on Function in C Programming
Shuvongkor Barman
 
U19CS101 - PPS Unit 4 PPT (1).ppt
Manivannan837728
 
Programming Fundamentals Functions in C and types
imtiazalijoono
 
POLITEKNIK MALAYSIA
Aiman Hud
 
unit_2 (1).pptx
JVenkateshGoud
 
Function oneshot with python programming .pptx
lionsconvent1234
 
Function in C Programming
Anil Pokhrel
 
unit_2.pptx
Venkatesh Goud
 
Lecture_5_-_Functions_in_C_Detailed.pptx
Salim Shadman Ankur
 
Chapter Introduction to Modular Programming.ppt
AmanuelZewdie4
 
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
harinipradeep15
 
Lecture 1_Functions in C.pptx
KhurramKhan173
 
arrays.ppt
Bharath904863
 
FUNCTIONengineeringtechnologyslidesh.pptx
ricknova674
 
FUNCTION.pptxfkrdutytrtttrrtttttttttttttt
hboi8164
 
C++ Functions.pptx
DikshaDani5
 
C FUNCTIONS
TeenaGeorge15
 
CH.4FUNCTIONS IN C (1).pptx
sangeeta borde
 
C functions by ranjan call by value and reference.pptx
ranjan317165
 
About the C program's basic function for beginner students
sabbirahmednomaninfo
 
Presentation on Function in C Programming
Shuvongkor Barman
 
Ad

More from santosh147365 (8)

PPTX
lightGen_presentatio you can see the new one in the given series of numbers n...
santosh147365
 
PPTX
VTUProj I think I will be going to temple ect-1.pptx
santosh147365
 
PPTX
Chapter_12_Regisfnfnjfjfjfjfjjtration.pptx
santosh147365
 
PPTX
Data_Security_inrefef_CloudComputing.pptx
santosh147365
 
PPTX
The-Power-of-Respect-in-Human-to-Human-Relationships.pptx
santosh147365
 
PPTX
hanuppt.pptx
santosh147365
 
PDF
3. Flow Controls in C (Part II).pdf
santosh147365
 
PDF
15EC81 - Robin Singla.pdf
santosh147365
 
lightGen_presentatio you can see the new one in the given series of numbers n...
santosh147365
 
VTUProj I think I will be going to temple ect-1.pptx
santosh147365
 
Chapter_12_Regisfnfnjfjfjfjfjjtration.pptx
santosh147365
 
Data_Security_inrefef_CloudComputing.pptx
santosh147365
 
The-Power-of-Respect-in-Human-to-Human-Relationships.pptx
santosh147365
 
hanuppt.pptx
santosh147365
 
3. Flow Controls in C (Part II).pdf
santosh147365
 
15EC81 - Robin Singla.pdf
santosh147365
 
Ad

Recently uploaded (20)

PPT
Lecture14-Probability of default and imp
icuphamid
 
PPTX
RTM_Module1_Summary_tyiuwyPresentation.pptx
DeepakKumar311204
 
PDF
NCHRP Report 672 Roundabouts: An Informational Guide
Forklift Trucks in Minnesota
 
PPTX
1 food management_ttttttR Chalasani.pptx
srinidhi24bba7002
 
PPTX
1.02 Ramesh Pinjani - Important Track Design Parameters.pptx
abheeplay
 
PDF
Transform Your Lexus for the Trails with Expert Off-Road Customization Services
MW4 Outfitters
 
PPTX
托莱多大学文凭办理|办理UT毕业证i20购买学位证书电子版
xxxihn4u
 
PPTX
July 2025 - Automobile_Industry_Trends_Presentation.pptx
savithrir7
 
PPTX
Detroit Business Travel Made Easy with Detroit DTW Cars
Detroit DTW Car
 
PDF
PC110R-1 Komatsu Hydraulic Excavator Parts Manual SN 2265010170-Up
Heavy Equipment Manual
 
PPTX
oA final ppt parmar vishal bca sem 1 .pptx
parmarvishal6790
 
PDF
deloitte-nl-integrated-annual-report-2018-2019.pdf
dsoham206
 
PPTX
power of social media hackertghfdgfgdfgdfggh
xoviva2925
 
PDF
TD-9H KOMATSU BULLDOZER PARTS MANUAL P045501-P046274
Heavy Equipment Manual
 
PPTX
INTRODUCTION TO HUMAN RESOURCE MANAGEMEN
FahadBinImtiaz
 
PPTX
PROPOSAL RESEARCH METHODOLOGY-1lssskkskes
IsaacAntwi15
 
PPTX
Distributed Systems (3rd Edition)Introduction
saadabinibrahim
 
PPTX
Have 10 Thousand Dollars Lying Around? You Can Buy Any One Of These Project Cars
jennifermiller8137
 
PPTX
Steps_Tutorial_1_Workforce Management.pptx
roshansharma586
 
PDF
Reliable Solutions for Maserati Battery, Wiring, and Electronics Problems You...
Kruse Lucas Imports
 
Lecture14-Probability of default and imp
icuphamid
 
RTM_Module1_Summary_tyiuwyPresentation.pptx
DeepakKumar311204
 
NCHRP Report 672 Roundabouts: An Informational Guide
Forklift Trucks in Minnesota
 
1 food management_ttttttR Chalasani.pptx
srinidhi24bba7002
 
1.02 Ramesh Pinjani - Important Track Design Parameters.pptx
abheeplay
 
Transform Your Lexus for the Trails with Expert Off-Road Customization Services
MW4 Outfitters
 
托莱多大学文凭办理|办理UT毕业证i20购买学位证书电子版
xxxihn4u
 
July 2025 - Automobile_Industry_Trends_Presentation.pptx
savithrir7
 
Detroit Business Travel Made Easy with Detroit DTW Cars
Detroit DTW Car
 
PC110R-1 Komatsu Hydraulic Excavator Parts Manual SN 2265010170-Up
Heavy Equipment Manual
 
oA final ppt parmar vishal bca sem 1 .pptx
parmarvishal6790
 
deloitte-nl-integrated-annual-report-2018-2019.pdf
dsoham206
 
power of social media hackertghfdgfgdfgdfggh
xoviva2925
 
TD-9H KOMATSU BULLDOZER PARTS MANUAL P045501-P046274
Heavy Equipment Manual
 
INTRODUCTION TO HUMAN RESOURCE MANAGEMEN
FahadBinImtiaz
 
PROPOSAL RESEARCH METHODOLOGY-1lssskkskes
IsaacAntwi15
 
Distributed Systems (3rd Edition)Introduction
saadabinibrahim
 
Have 10 Thousand Dollars Lying Around? You Can Buy Any One Of These Project Cars
jennifermiller8137
 
Steps_Tutorial_1_Workforce Management.pptx
roshansharma586
 
Reliable Solutions for Maserati Battery, Wiring, and Electronics Problems You...
Kruse Lucas Imports
 

5. Functions in C.pdf

  • 2. What is Function? • A function is a block of code that performs a specific task. • A function only runs when it is called. • You can pass data, known as parameters, into a function. • Functions are used to perform certain actions, and they are important for reusing code: Define the code once, and use it many times.
  • 3. Types of function • There are two types of function in C programming: 1. Standard library functions (Pre-Defined Functions) 2. User-defined functions
  • 4. 1. Standard library functions (Pre-Defined Functions) • The standard library functions are built-in functions in C programming. • These functions are defined in header files. For example, The printf() is a standard library function to display formatted output to the screen. This function is defined in the stdio.h header file. Hence to use printf() function, we need to include the stdio.h header file using #include <stdio.h>. The sqrt() function calculates the square root of a number. The function is defined in the math.h header file
  • 5. 2. User-defined functions • User-defined functions are a block of code written by the user to perform a specific action. A user-defined function has a return type, a function name, parameters, and body of the function. Function can be called using the unique name of the function followed by function parameters passed inside round brackets ().
  • 6. Advantages of user-defined function The program will be easier to understand, maintain and debug. Reusable codes that can be used in other programs A large program can be divided into smaller modules. Hence, a large project can be divided among many programmers.
  • 8. How function works • The execution of a C program begins from the main() function • When the compiler encounters functionname() control of the program jumps to void functionname() • And, the compiler starts executing the codes inside functionname(). • The control of the program jumps back to the main() function once code inside the function definition is executed.
  • 9. #include <stdio.h> int addNumbers(int a, int b); // function prototype int addNumbers(int a, int b) // function definition { int result; result = a+b; return result; // return statement } void main() { int n1,n2,sum; printf("Enters two numbers: "); scanf("%d %d",&n1,&n2); sum = addNumbers(n1, n2); // function call printf("sum = %d",sum); } Example of user-defined function