SlideShare une entreprise Scribd logo
1  sur  9
Télécharger pour lire hors ligne
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.
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

Contenu connexe

Similaire à 5. Functions in C.pdf

Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptAmanuelZewdie4
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxKhurramKhan173
 
C++ Functions.pptx
C++ Functions.pptxC++ Functions.pptx
C++ Functions.pptxDikshaDani5
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxsangeeta borde
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C ProgrammingShuvongkor Barman
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptxSKUP1
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptxLECO9
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1YOGESH SINGH
 
Unit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptxUnit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptxsaivasu4
 
Function in c programming
Function in c programmingFunction in c programming
Function in c programmingSayeemAhmed8
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxSKUP1
 

Similaire à 5. Functions in C.pdf (20)

unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
 
C++ Functions.pptx
C++ Functions.pptxC++ Functions.pptx
C++ Functions.pptx
 
C FUNCTIONS
C FUNCTIONSC FUNCTIONS
C FUNCTIONS
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
FUNCTIONS.pptx
FUNCTIONS.pptxFUNCTIONS.pptx
FUNCTIONS.pptx
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
C structure
C structureC structure
C structure
 
Functions
Functions Functions
Functions
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
Basic c++
Basic c++Basic c++
Basic c++
 
Unit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptxUnit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptx
 
Function in c programming
Function in c programmingFunction in c programming
Function in c programming
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptx
 

Dernier

Majestic Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...
Majestic Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...Majestic Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...
Majestic Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...amitlee9823
 
Muslim Call Girls Churchgate WhatsApp +91-9930687706, Best Service
Muslim Call Girls Churchgate WhatsApp +91-9930687706, Best ServiceMuslim Call Girls Churchgate WhatsApp +91-9930687706, Best Service
Muslim Call Girls Churchgate WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
FULL NIGHT — 9999894380 Call Girls In Jagat Puri | Delhi
FULL NIGHT — 9999894380 Call Girls In Jagat Puri | DelhiFULL NIGHT — 9999894380 Call Girls In Jagat Puri | Delhi
FULL NIGHT — 9999894380 Call Girls In Jagat Puri | DelhiSaketCallGirlsCallUs
 
Vip Mumbai Call Girls Panvel Call On 9920725232 With Body to body massage wit...
Vip Mumbai Call Girls Panvel Call On 9920725232 With Body to body massage wit...Vip Mumbai Call Girls Panvel Call On 9920725232 With Body to body massage wit...
Vip Mumbai Call Girls Panvel Call On 9920725232 With Body to body massage wit...amitlee9823
 
如何办理(NCL毕业证书)纽卡斯尔大学毕业证毕业证成绩单原版一比一
如何办理(NCL毕业证书)纽卡斯尔大学毕业证毕业证成绩单原版一比一如何办理(NCL毕业证书)纽卡斯尔大学毕业证毕业证成绩单原版一比一
如何办理(NCL毕业证书)纽卡斯尔大学毕业证毕业证成绩单原版一比一avy6anjnd
 
Call Girls Bangalore Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Bangalore Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Bangalore Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Bangalore Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...amitlee9823
 
Just Call Vip call girls Kovalam Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls Kovalam Escorts ☎️9352988975 Two shot with one girl ...Just Call Vip call girls Kovalam Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls Kovalam Escorts ☎️9352988975 Two shot with one girl ...gajnagarg
 
BOOK FARIDABAD CALL GIRL(VIP Sunny Leone) @8168257667 BOOK 24/7
BOOK FARIDABAD CALL GIRL(VIP Sunny Leone) @8168257667 BOOK  24/7BOOK FARIDABAD CALL GIRL(VIP Sunny Leone) @8168257667 BOOK  24/7
BOOK FARIDABAD CALL GIRL(VIP Sunny Leone) @8168257667 BOOK 24/7Hyderabad Escorts Agency
 
Call Girls Hongasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Hongasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Hongasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Hongasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一
如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一
如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一ozave
 
FARIDABAD CALL GIRL Anal shot #8168257667 BOOK Shilpa 7999/-
FARIDABAD  CALL GIRL Anal shot #8168257667  BOOK Shilpa 7999/-FARIDABAD  CALL GIRL Anal shot #8168257667  BOOK Shilpa 7999/-
FARIDABAD CALL GIRL Anal shot #8168257667 BOOK Shilpa 7999/-Hyderabad Escorts Agency
 
Is Your BMW PDC Malfunctioning Discover How to Easily Reset It
Is Your BMW PDC Malfunctioning Discover How to Easily Reset ItIs Your BMW PDC Malfunctioning Discover How to Easily Reset It
Is Your BMW PDC Malfunctioning Discover How to Easily Reset ItEuroService Automotive
 
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...nirzagarg
 
Just Call Vip call girls Ankleshwar Escorts ☎️9352988975 Two shot with one gi...
Just Call Vip call girls Ankleshwar Escorts ☎️9352988975 Two shot with one gi...Just Call Vip call girls Ankleshwar Escorts ☎️9352988975 Two shot with one gi...
Just Call Vip call girls Ankleshwar Escorts ☎️9352988975 Two shot with one gi...gajnagarg
 
8377087607, Door Step Call Girls In Majnu Ka Tilla (Delhi) 24/7 Available
8377087607, Door Step Call Girls In Majnu Ka Tilla (Delhi) 24/7 Available8377087607, Door Step Call Girls In Majnu Ka Tilla (Delhi) 24/7 Available
8377087607, Door Step Call Girls In Majnu Ka Tilla (Delhi) 24/7 Availabledollysharma2066
 
➥🔝 7737669865 🔝▻ Asansol Call-girls in Women Seeking Men 🔝Asansol🔝 Escorts...
➥🔝 7737669865 🔝▻ Asansol Call-girls in Women Seeking Men  🔝Asansol🔝   Escorts...➥🔝 7737669865 🔝▻ Asansol Call-girls in Women Seeking Men  🔝Asansol🔝   Escorts...
➥🔝 7737669865 🔝▻ Asansol Call-girls in Women Seeking Men 🔝Asansol🔝 Escorts...amitlee9823
 
ELECTRICITÉ TMT 55.pdf electrick diagram manitout
ELECTRICITÉ TMT 55.pdf electrick diagram manitoutELECTRICITÉ TMT 55.pdf electrick diagram manitout
ELECTRICITÉ TMT 55.pdf electrick diagram manitoutssjews46
 
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...amitlee9823
 
➥🔝 7737669865 🔝▻ Bhiwandi Call-girls in Women Seeking Men 🔝Bhiwandi🔝 Escor...
➥🔝 7737669865 🔝▻ Bhiwandi Call-girls in Women Seeking Men  🔝Bhiwandi🔝   Escor...➥🔝 7737669865 🔝▻ Bhiwandi Call-girls in Women Seeking Men  🔝Bhiwandi🔝   Escor...
➥🔝 7737669865 🔝▻ Bhiwandi Call-girls in Women Seeking Men 🔝Bhiwandi🔝 Escor...amitlee9823
 

Dernier (20)

Majestic Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...
Majestic Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...Majestic Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...
Majestic Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...
 
Muslim Call Girls Churchgate WhatsApp +91-9930687706, Best Service
Muslim Call Girls Churchgate WhatsApp +91-9930687706, Best ServiceMuslim Call Girls Churchgate WhatsApp +91-9930687706, Best Service
Muslim Call Girls Churchgate WhatsApp +91-9930687706, Best Service
 
FULL NIGHT — 9999894380 Call Girls In Jagat Puri | Delhi
FULL NIGHT — 9999894380 Call Girls In Jagat Puri | DelhiFULL NIGHT — 9999894380 Call Girls In Jagat Puri | Delhi
FULL NIGHT — 9999894380 Call Girls In Jagat Puri | Delhi
 
Vip Mumbai Call Girls Panvel Call On 9920725232 With Body to body massage wit...
Vip Mumbai Call Girls Panvel Call On 9920725232 With Body to body massage wit...Vip Mumbai Call Girls Panvel Call On 9920725232 With Body to body massage wit...
Vip Mumbai Call Girls Panvel Call On 9920725232 With Body to body massage wit...
 
如何办理(NCL毕业证书)纽卡斯尔大学毕业证毕业证成绩单原版一比一
如何办理(NCL毕业证书)纽卡斯尔大学毕业证毕业证成绩单原版一比一如何办理(NCL毕业证书)纽卡斯尔大学毕业证毕业证成绩单原版一比一
如何办理(NCL毕业证书)纽卡斯尔大学毕业证毕业证成绩单原版一比一
 
Call Girls Bangalore Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Bangalore Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Bangalore Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Bangalore Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
Just Call Vip call girls Kovalam Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls Kovalam Escorts ☎️9352988975 Two shot with one girl ...Just Call Vip call girls Kovalam Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls Kovalam Escorts ☎️9352988975 Two shot with one girl ...
 
BOOK FARIDABAD CALL GIRL(VIP Sunny Leone) @8168257667 BOOK 24/7
BOOK FARIDABAD CALL GIRL(VIP Sunny Leone) @8168257667 BOOK  24/7BOOK FARIDABAD CALL GIRL(VIP Sunny Leone) @8168257667 BOOK  24/7
BOOK FARIDABAD CALL GIRL(VIP Sunny Leone) @8168257667 BOOK 24/7
 
Call Girls Hongasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Hongasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Hongasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Hongasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
(INDIRA) Call Girl Nashik Call Now 8617697112 Nashik Escorts 24x7
(INDIRA) Call Girl Nashik Call Now 8617697112 Nashik Escorts 24x7(INDIRA) Call Girl Nashik Call Now 8617697112 Nashik Escorts 24x7
(INDIRA) Call Girl Nashik Call Now 8617697112 Nashik Escorts 24x7
 
如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一
如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一
如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一
 
FARIDABAD CALL GIRL Anal shot #8168257667 BOOK Shilpa 7999/-
FARIDABAD  CALL GIRL Anal shot #8168257667  BOOK Shilpa 7999/-FARIDABAD  CALL GIRL Anal shot #8168257667  BOOK Shilpa 7999/-
FARIDABAD CALL GIRL Anal shot #8168257667 BOOK Shilpa 7999/-
 
Is Your BMW PDC Malfunctioning Discover How to Easily Reset It
Is Your BMW PDC Malfunctioning Discover How to Easily Reset ItIs Your BMW PDC Malfunctioning Discover How to Easily Reset It
Is Your BMW PDC Malfunctioning Discover How to Easily Reset It
 
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
 
Just Call Vip call girls Ankleshwar Escorts ☎️9352988975 Two shot with one gi...
Just Call Vip call girls Ankleshwar Escorts ☎️9352988975 Two shot with one gi...Just Call Vip call girls Ankleshwar Escorts ☎️9352988975 Two shot with one gi...
Just Call Vip call girls Ankleshwar Escorts ☎️9352988975 Two shot with one gi...
 
8377087607, Door Step Call Girls In Majnu Ka Tilla (Delhi) 24/7 Available
8377087607, Door Step Call Girls In Majnu Ka Tilla (Delhi) 24/7 Available8377087607, Door Step Call Girls In Majnu Ka Tilla (Delhi) 24/7 Available
8377087607, Door Step Call Girls In Majnu Ka Tilla (Delhi) 24/7 Available
 
➥🔝 7737669865 🔝▻ Asansol Call-girls in Women Seeking Men 🔝Asansol🔝 Escorts...
➥🔝 7737669865 🔝▻ Asansol Call-girls in Women Seeking Men  🔝Asansol🔝   Escorts...➥🔝 7737669865 🔝▻ Asansol Call-girls in Women Seeking Men  🔝Asansol🔝   Escorts...
➥🔝 7737669865 🔝▻ Asansol Call-girls in Women Seeking Men 🔝Asansol🔝 Escorts...
 
ELECTRICITÉ TMT 55.pdf electrick diagram manitout
ELECTRICITÉ TMT 55.pdf electrick diagram manitoutELECTRICITÉ TMT 55.pdf electrick diagram manitout
ELECTRICITÉ TMT 55.pdf electrick diagram manitout
 
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
 
➥🔝 7737669865 🔝▻ Bhiwandi Call-girls in Women Seeking Men 🔝Bhiwandi🔝 Escor...
➥🔝 7737669865 🔝▻ Bhiwandi Call-girls in Women Seeking Men  🔝Bhiwandi🔝   Escor...➥🔝 7737669865 🔝▻ Bhiwandi Call-girls in Women Seeking Men  🔝Bhiwandi🔝   Escor...
➥🔝 7737669865 🔝▻ Bhiwandi Call-girls in Women Seeking Men 🔝Bhiwandi🔝 Escor...
 

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.
  • 7.
  • 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