SlideShare a Scribd company logo
1 of 13
Function in
Programming Language
(C & C++)
Guided by-
All Teachers
Presented by –
Rahul Sahu
B.Sc.- 2nd Year (CS)
Definition:-
A large program can be divided into a series of
individual related programs called “Modules”.
These Modules are called “Function”.
The function can be classified into two
categories –
i. In-Built Function
ii. User Defined Function
Defining a function: -
return type_function name(Argument)
{
----------------------------
Body of function
----------------------------
}
i. Return type
ii. Function name
iii. Argument
iv. Body of function
Element of User Defined
Function:-
Three elements of User Defined Function –
i. Function Declaration
ii. Function Definition
iii. Function Calling
Function Declaration:-
Function are like variables. As variables
are declared before they are used, we
normally declare the function before they
are defined and end with semicolon. This
is called Function Declaration.
Example:- int add();
float per();
Function Definition:-
The program module that is written to
achieve a specific task is called Function
Definition .
Example:-
add() add()
{ {
int a,b,c; int a,b,c;
scanf(“%d %d”,&a,&b); cin>>a>>b;
c=a+b; c=a+b;
printf(“n %d”,&c); cout<<c;
} }
Function Calling:-
We know that execution always start from
main function. If we want to use the
function that we have just discussed, it
has to be invoke. This is called Function
Call.
Example:- void main( )
{
add( );
}
Example:-
#include<stdio.h> #include<iostream.h>
#include<conio.h> #include<conio.h>
int add( int a, int b) int add(int a, int b)
{ {
int c; int c;
c=a+b ; c=a+b;
printf(“n %d”,c); cout<<“addition of no.=“<<c;
} }
void main ( ) void main( )
{ {
add(2,3 ); add(3,4);
} }
Output:- 5 Output:- addition of no. 7
Argument or Parameter:-
The Argument or Parameter can be classified into
two categories –
i. Formal Argument
Example:- int add( int ,int)
ii. Actual Argument
Example:- add(4,5)
Passing Argument to
function:-
Two type of Passing Argument to function –
i. Call By Value
ii. Call By Reference
Call By Value:-
When a function is called with actual
parameters, the values of actual parameters
are copied into formal parameters. If the
values of the formal parameter change in
the function, the values of the actual
parameters are not changed. This way of
passing, parameters is called “Pass by Value”
or “Call by Value”.
Call By Reference:-
In call by reference, a function is called with
addresses of actual parameters. In the
function header, the formal parameters
receive the addresses of actual parameters.
Now, the formal parameters do not contain
values, instead they contain addresses. Any
variable if it contain an address, it is called a
pointer variable. Using pointer variables, the
values of the actual parameters can be
changed. This way of passing parameters is
called “Pass by Reference” or “Call by
Reference”.
Thank You

More Related Content

What's hot

What's hot (20)

Functions in c
Functions in cFunctions in c
Functions in c
 
Function in C Language
Function in C Language Function in C Language
Function in C Language
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 
Function lecture
Function lectureFunction lecture
Function lecture
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Built in function
Built in functionBuilt in function
Built in function
 
Functions in c
Functions in cFunctions in c
Functions in c
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Functionincprogram
FunctionincprogramFunctionincprogram
Functionincprogram
 
Function in C program
Function in C programFunction in C program
Function in C program
 
C structure
C structureC structure
C structure
 
Function in C
Function in CFunction in C
Function in C
 
Functions in C
Functions in CFunctions in C
Functions in C
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
 
C function
C functionC function
C function
 

Similar to Function in C and C++

Prsentation on functions
Prsentation on functionsPrsentation on functions
Prsentation on functions
Alisha Korpal
 

Similar to Function in C and C++ (20)

unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdf
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
Functions part1
Functions part1Functions part1
Functions part1
 
Fnctions part2
Fnctions part2Fnctions part2
Fnctions part2
 
Functions
FunctionsFunctions
Functions
 
functions in c language_functions in c language.pptx
functions in c language_functions in c language.pptxfunctions in c language_functions in c language.pptx
functions in c language_functions in c language.pptx
 
Functions assignment
Functions assignmentFunctions assignment
Functions assignment
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdf
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptx
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functions
 
Functions
Functions Functions
Functions
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
 
Prsentation on functions
Prsentation on functionsPrsentation on functions
Prsentation on functions
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
 
user defined functions in c language
user defined functions in c languageuser defined functions in c language
user defined functions in c language
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 

Function in C and C++

  • 1. Function in Programming Language (C & C++) Guided by- All Teachers Presented by – Rahul Sahu B.Sc.- 2nd Year (CS)
  • 2. Definition:- A large program can be divided into a series of individual related programs called “Modules”. These Modules are called “Function”. The function can be classified into two categories – i. In-Built Function ii. User Defined Function
  • 3. Defining a function: - return type_function name(Argument) { ---------------------------- Body of function ---------------------------- } i. Return type ii. Function name iii. Argument iv. Body of function
  • 4. Element of User Defined Function:- Three elements of User Defined Function – i. Function Declaration ii. Function Definition iii. Function Calling
  • 5. Function Declaration:- Function are like variables. As variables are declared before they are used, we normally declare the function before they are defined and end with semicolon. This is called Function Declaration. Example:- int add(); float per();
  • 6. Function Definition:- The program module that is written to achieve a specific task is called Function Definition . Example:- add() add() { { int a,b,c; int a,b,c; scanf(“%d %d”,&a,&b); cin>>a>>b; c=a+b; c=a+b; printf(“n %d”,&c); cout<<c; } }
  • 7. Function Calling:- We know that execution always start from main function. If we want to use the function that we have just discussed, it has to be invoke. This is called Function Call. Example:- void main( ) { add( ); }
  • 8. Example:- #include<stdio.h> #include<iostream.h> #include<conio.h> #include<conio.h> int add( int a, int b) int add(int a, int b) { { int c; int c; c=a+b ; c=a+b; printf(“n %d”,c); cout<<“addition of no.=“<<c; } } void main ( ) void main( ) { { add(2,3 ); add(3,4); } } Output:- 5 Output:- addition of no. 7
  • 9. Argument or Parameter:- The Argument or Parameter can be classified into two categories – i. Formal Argument Example:- int add( int ,int) ii. Actual Argument Example:- add(4,5)
  • 10. Passing Argument to function:- Two type of Passing Argument to function – i. Call By Value ii. Call By Reference
  • 11. Call By Value:- When a function is called with actual parameters, the values of actual parameters are copied into formal parameters. If the values of the formal parameter change in the function, the values of the actual parameters are not changed. This way of passing, parameters is called “Pass by Value” or “Call by Value”.
  • 12. Call By Reference:- In call by reference, a function is called with addresses of actual parameters. In the function header, the formal parameters receive the addresses of actual parameters. Now, the formal parameters do not contain values, instead they contain addresses. Any variable if it contain an address, it is called a pointer variable. Using pointer variables, the values of the actual parameters can be changed. This way of passing parameters is called “Pass by Reference” or “Call by Reference”.