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
PPTX
Functions and Header files ver very useful
PPTX
PPTX
The function contains the set of programming statements enclosed by {}  when ...
PPTX
functions in c-1.pptxfunctions in c-1.pptx
PPTX
Chapter One Function.pptx
PPTX
Funtions of c programming. the functions of c helps to clarify all the tops
PPTX
Chapter 1 (2) array and structure r.pptx
Functions and structure in programming c
Functions and Header files ver very useful
The function contains the set of programming statements enclosed by {}  when ...
functions in c-1.pptxfunctions in c-1.pptx
Chapter One Function.pptx
Funtions of c programming. the functions of c helps to clarify all the tops
Chapter 1 (2) array and structure r.pptx

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

PPTX
DS functions-1.pptx
PPT
U19CS101 - PPS Unit 4 PPT (1).ppt
PDF
Programming Fundamentals Functions in C and types
PPT
POLITEKNIK MALAYSIA
PPTX
unit_2 (1).pptx
PPTX
Function oneshot with python programming .pptx
PPTX
Function in C Programming
PPTX
unit_2.pptx
PPTX
Lecture_5_-_Functions_in_C_Detailed.pptx
PPT
Chapter Introduction to Modular Programming.ppt
PPT
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
PPTX
Lecture 1_Functions in C.pptx
PPT
arrays.ppt
PPTX
FUNCTIONengineeringtechnologyslidesh.pptx
PPTX
FUNCTION.pptxfkrdutytrtttrrtttttttttttttt
PPTX
C++ Functions.pptx
PPT
C FUNCTIONS
PPTX
CH.4FUNCTIONS IN C (1).pptx
PPTX
C functions by ranjan call by value and reference.pptx
PPTX
About the C program's basic function for beginner students
DS functions-1.pptx
U19CS101 - PPS Unit 4 PPT (1).ppt
Programming Fundamentals Functions in C and types
POLITEKNIK MALAYSIA
unit_2 (1).pptx
Function oneshot with python programming .pptx
Function in C Programming
unit_2.pptx
Lecture_5_-_Functions_in_C_Detailed.pptx
Chapter Introduction to Modular Programming.ppt
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
Lecture 1_Functions in C.pptx
arrays.ppt
FUNCTIONengineeringtechnologyslidesh.pptx
FUNCTION.pptxfkrdutytrtttrrtttttttttttttt
C++ Functions.pptx
C FUNCTIONS
CH.4FUNCTIONS IN C (1).pptx
C functions by ranjan call by value and reference.pptx
About the C program's basic function for beginner students
Ad

More from santosh147365 (8)

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

Recently uploaded (20)

PDF
MES Chapter 3 Combined UNIVERSITY OF VISVESHWARAYA
PDF
Compact Excavator Volvo EC55 Service Repair Manual.pdf
PPT
Internal combustion system for the engine fuel system
PDF
Smart_Doors_Trunk_Control_Presentation.pdf
PPT
Main/Core Business Application User Manual
PPTX
Constitutional Design PPT.pptxl from social science class IX
PPTX
7 BAB 1 UNSUR SENI RUPA (WARNA) whefkwbefkwjebfkwejbbfkkwejbfkwjefbkwjefbw.pptx
PDF
Pistons Volvo EC160C NL EC160CNL Excavator Service Repair Manual.pdf
PDF
System Diagrams John Deere 370E 410E 460E Repair Manual.pdf
DOC
EAU-960 COMBINED INJECTION AND IGNITION SYSTEM WITH ELECTRONIC REGULATION.doc
PPTX
368455847-Relibility RJS-Relibility-PPT-1.pptx
PPTX
description of motor equipments and its process.pptx
PDF
Lightweight-and-quantum-resistant-authentication-for-the-Internet-of-Drones-I...
PDF
John Deere 460E II Articulated Dump Truck Service Manual.pdf
PPTX
diesel comman rail diesel comman hhh rail
PDF
Fuel injection pump Volvo EC55 Repair Manual.pdf
PDF
Deutz D6D EBE2 Volvo EC160BLC Excavator Service Repair Manual.pdf
PDF
120K 2 caterpillar motor grader service repair manual SZZ
PDF
TM1611 John Deere 410E service Repair Manual.pdf
PDF
Engine Volvo EC55 Compact Excavator Service Repair Manual.pdf
MES Chapter 3 Combined UNIVERSITY OF VISVESHWARAYA
Compact Excavator Volvo EC55 Service Repair Manual.pdf
Internal combustion system for the engine fuel system
Smart_Doors_Trunk_Control_Presentation.pdf
Main/Core Business Application User Manual
Constitutional Design PPT.pptxl from social science class IX
7 BAB 1 UNSUR SENI RUPA (WARNA) whefkwbefkwjebfkwejbbfkkwejbfkwjefbkwjefbw.pptx
Pistons Volvo EC160C NL EC160CNL Excavator Service Repair Manual.pdf
System Diagrams John Deere 370E 410E 460E Repair Manual.pdf
EAU-960 COMBINED INJECTION AND IGNITION SYSTEM WITH ELECTRONIC REGULATION.doc
368455847-Relibility RJS-Relibility-PPT-1.pptx
description of motor equipments and its process.pptx
Lightweight-and-quantum-resistant-authentication-for-the-Internet-of-Drones-I...
John Deere 460E II Articulated Dump Truck Service Manual.pdf
diesel comman rail diesel comman hhh rail
Fuel injection pump Volvo EC55 Repair Manual.pdf
Deutz D6D EBE2 Volvo EC160BLC Excavator Service Repair Manual.pdf
120K 2 caterpillar motor grader service repair manual SZZ
TM1611 John Deere 410E service Repair Manual.pdf
Engine Volvo EC55 Compact Excavator Service Repair Manual.pdf

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