SlideShare a Scribd company logo
Function Call
by
Value & Reference
By: Arijit Dhali
Contents
2
User Defined Function
Common Method of Swapping
Integers
Call by Value
Call by Reference
Differences
Conclusion
User Defined Function
A user-defined function is a function provided by the
user of a program or environment, in a context where
the usual assumption is that functions are built into
the program or environment.
Syntax:
return_type function_name (parameter list)
{
Function Body
return statement;
}
3
Common Method of Swapping Two Integers
4
#include<stdio.h>
main()
{
int x, y, z;
printf (“n Enter the value of x: ");
scanf ("%d", &x);
printf (“n Enter the value of y: ");
scanf ("%d", &y);
z = x;
x = y;
y = z;
printf ( "n After swap : x = %d, y = %d n", x, y);
return 0;
}
Using Third Variable
Source Code:
Storing Value
Storing Value
Swap using 3rd
Variable
Declaring Variable
5
Output:
Values Get Swapped
6
Call by Value
The call by value method of passing argument to a function, copies
the actual value of an argument into the formal parameter of the
function. In this case, changed made to parameter inside the function
had no effect on argument.
7
#include<stdio.h>
void swapvalue(int x,int y);
int main()
{
int a,b;
printf(“n Enter two numbers: ");
scanf("%d %d",&a,&b);
printf(“n Before Swapping a=%d, b=%d n",a,b);
swapvalue(a,b);
printf(“n After Swapping a=%d, b=%d n",a,b);
return 0;
}
void swapvalue(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
return;
}
Source Code:
Swap using 3rd
Variable
Function Definition
Function Declaration
Declaring Variable
Function Calling
Passing Variable
8
Output:
Values Doesn’t Swap
9
Call by Reference
The Call by Reference method of passing arguments to a function copies
the address of an argument into the formal parameter. Inside the function,
the address is used to access the actual argument used in the call. This
means that changes made to be parameter affect the passed argument. To
pass the value by reference, argument pointers are passed to the functions
just like any other value. So, accordingly you need to declare the function
parameters as pointer types as in the following swap(), which exchanges
the values of the two integer variables pointed to by its arguments.
10
#include<stdio.h>
void swapreference(int *x,int *y);
int main()
{
int a,b;
printf(“n Enter two numbers: ");
scanf("%d %d",&a,&b);
printf(“n Before Swapping a=%d, b=%d",a,b);
swapreference(&a,&b);
printf(“n After Swapping a=%d, b=%d",a,b);
return 0;
}
void swapreference(int *x, int *y)
{
int temp=0;
temp=*x;
*x=*y;
*y=temp;
return;
}
Source Code:
Swapping
address using
3rd Variable
Function Calling
Passing Address
Function Definition along
with defining Pointer
Function Declaration
Declaring Variable
11
Output:
Values Get Swapped
› The function is called by
directly passing value of
variable as argument.
› We need to declare a
general variable as function
argument.
› Changes made in the formal
parameters will not be
reflected in the actual
parameters. It is because
formal and actual
parameters are stored in
different locations.
Call by Value v/s Call by Reference
› The function is called by
directly passing address of
variable as argument.
› We need to declare pointer
variable as function
argument.
› Changes made in the formal
parameters will be reflected
in the actual parameters. It is
because formal and actual
parameters are stored in
same locations.
12
Call by Value Call by Reference
13
Conclusion
As the Conclusion , If we want to pass only the value of variable use ‘call by
value’ approach, and if you want to see the change in the original value of the
variable then use ‘call by reference’ approach.
GRACIAS
14
Hope to see you again!!!

More Related Content

What's hot

C pointer
C pointerC pointer
Function in c program
Function in c programFunction in c program
Function in c program
umesh patil
 
File handling in c
File handling in cFile handling in c
File handling in c
aakanksha s
 
Enums in c
Enums in cEnums in c
Functions in c
Functions in cFunctions in c
Functions in c
sunila tharagaturi
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
Dr-Dipali Meher
 
File handling in C
File handling in CFile handling in C
File handling in C
Kamal Acharya
 
Branching statements
Branching statementsBranching statements
Branching statements
ArunMK17
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
Anil Pokhrel
 
POINTERS IN C
POINTERS IN CPOINTERS IN C
POINTERS IN C
Neel Mungra
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
MohammadSalman129
 
File in C language
File in C languageFile in C language
File in C language
Manash Kumar Mondal
 
structure and union
structure and unionstructure and union
structure and unionstudent
 
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
imtiazalijoono
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 
User defined functions
User defined functionsUser defined functions
User defined functions
Rokonuzzaman Rony
 

What's hot (20)

C pointer
C pointerC pointer
C pointer
 
Function in c program
Function in c programFunction in c program
Function in c program
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Enums in c
Enums in cEnums in c
Enums in c
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Function
FunctionFunction
Function
 
File handling in C
File handling in CFile handling in C
File handling in C
 
Branching statements
Branching statementsBranching statements
Branching statements
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
POINTERS IN C
POINTERS IN CPOINTERS IN C
POINTERS IN C
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
 
File in C language
File in C languageFile in C language
File in C language
 
structure and union
structure and unionstructure and union
structure and union
 
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
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
 
User defined functions
User defined functionsUser defined functions
User defined functions
 

Similar to Types of function call

Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
Saranya saran
 
chapter-7 slide.pptx
chapter-7 slide.pptxchapter-7 slide.pptx
chapter-7 slide.pptx
cricketreview
 
Function in c
Function in cFunction in c
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
MKalpanaDevi
 
Unit 4 (1)
Unit 4 (1)Unit 4 (1)
Unit 4 (1)
psaravanan1985
 
Array Cont
Array ContArray Cont
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
AmIt Prasad
 
Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
Janani Satheshkumar
 
1. DSA - Introduction.pptx
1. DSA - Introduction.pptx1. DSA - Introduction.pptx
1. DSA - Introduction.pptx
hara69
 
Functions in C++.pdf
Functions in C++.pdfFunctions in C++.pdf
Functions in C++.pdf
LadallaRajKumar
 
C function
C functionC function
C function
thirumalaikumar3
 
Fundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptxFundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptx
Chandrakant Divate
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloadingankush_kumar
 
cp Module4(1)
cp Module4(1)cp Module4(1)
cp Module4(1)
Amarjith C K
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
s170883BesiVyshnavi
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
UMA PARAMESWARI
 
User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in C
RAJ KUMAR
 
presentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptpresentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.ppt
SandipPradhan23
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
NagasaiT
 

Similar to Types of function call (20)

Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
chapter-7 slide.pptx
chapter-7 slide.pptxchapter-7 slide.pptx
chapter-7 slide.pptx
 
Function in c
Function in cFunction in c
Function in c
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
Unit 4 (1)
Unit 4 (1)Unit 4 (1)
Unit 4 (1)
 
Array Cont
Array ContArray Cont
Array Cont
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
 
Function in c
Function in cFunction in c
Function in c
 
Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
 
1. DSA - Introduction.pptx
1. DSA - Introduction.pptx1. DSA - Introduction.pptx
1. DSA - Introduction.pptx
 
Functions in C++.pdf
Functions in C++.pdfFunctions in C++.pdf
Functions in C++.pdf
 
C function
C functionC function
C function
 
Fundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptxFundamentals of functions in C program.pptx
Fundamentals of functions in C program.pptx
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
 
cp Module4(1)
cp Module4(1)cp Module4(1)
cp Module4(1)
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
 
User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in C
 
presentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptpresentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.ppt
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
 

More from ArijitDhali

Signal Constellation, Geometric Interpretation of Signals
Signal Constellation,  Geometric Interpretation of  SignalsSignal Constellation,  Geometric Interpretation of  Signals
Signal Constellation, Geometric Interpretation of Signals
ArijitDhali
 
Stack Queue SubRoutine
Stack Queue SubRoutineStack Queue SubRoutine
Stack Queue SubRoutine
ArijitDhali
 
Overviewing the techniques of Numerical Integration.pdf
Overviewing the techniques of Numerical Integration.pdfOverviewing the techniques of Numerical Integration.pdf
Overviewing the techniques of Numerical Integration.pdf
ArijitDhali
 
Motorola 68020.pdf
Motorola 68020.pdfMotorola 68020.pdf
Motorola 68020.pdf
ArijitDhali
 
Stereotactic Radiosurgery in Brain Metastases.pdf
Stereotactic Radiosurgery in Brain Metastases.pdfStereotactic Radiosurgery in Brain Metastases.pdf
Stereotactic Radiosurgery in Brain Metastases.pdf
ArijitDhali
 
Active Filters.pdf
Active Filters.pdfActive Filters.pdf
Active Filters.pdf
ArijitDhali
 
Wideband Frequency Modulation.pdf
Wideband Frequency Modulation.pdfWideband Frequency Modulation.pdf
Wideband Frequency Modulation.pdf
ArijitDhali
 
Celebrity Problem.pdf
Celebrity Problem.pdfCelebrity Problem.pdf
Celebrity Problem.pdf
ArijitDhali
 
SSBSC Single Side Band - Suppressed Carrier Compressed
SSBSC Single Side Band - Suppressed Carrier CompressedSSBSC Single Side Band - Suppressed Carrier Compressed
SSBSC Single Side Band - Suppressed Carrier Compressed
ArijitDhali
 
Biodiversity Hotspots in India
Biodiversity Hotspots in IndiaBiodiversity Hotspots in India
Biodiversity Hotspots in India
ArijitDhali
 
LTI Systems - With/Without Memory
LTI Systems - With/Without MemoryLTI Systems - With/Without Memory
LTI Systems - With/Without Memory
ArijitDhali
 
RLC Series Resonance
RLC Series ResonanceRLC Series Resonance
RLC Series Resonance
ArijitDhali
 
Bivariate Discrete Distribution
Bivariate Discrete DistributionBivariate Discrete Distribution
Bivariate Discrete Distribution
ArijitDhali
 
Solar Cell
Solar CellSolar Cell
Solar Cell
ArijitDhali
 
Barcode Decoder
Barcode DecoderBarcode Decoder
Barcode Decoder
ArijitDhali
 
Dijkstra's Algorithm
Dijkstra's AlgorithmDijkstra's Algorithm
Dijkstra's Algorithm
ArijitDhali
 
Conditional Probability
Conditional ProbabilityConditional Probability
Conditional Probability
ArijitDhali
 
Isomerism of Transition Metal Complex
Isomerism of Transition Metal ComplexIsomerism of Transition Metal Complex
Isomerism of Transition Metal Complex
ArijitDhali
 
Space Solar Power
Space Solar PowerSpace Solar Power
Space Solar Power
ArijitDhali
 
Power Series - Legendre Polynomial - Bessel's Equation
Power Series - Legendre Polynomial - Bessel's EquationPower Series - Legendre Polynomial - Bessel's Equation
Power Series - Legendre Polynomial - Bessel's Equation
ArijitDhali
 

More from ArijitDhali (20)

Signal Constellation, Geometric Interpretation of Signals
Signal Constellation,  Geometric Interpretation of  SignalsSignal Constellation,  Geometric Interpretation of  Signals
Signal Constellation, Geometric Interpretation of Signals
 
Stack Queue SubRoutine
Stack Queue SubRoutineStack Queue SubRoutine
Stack Queue SubRoutine
 
Overviewing the techniques of Numerical Integration.pdf
Overviewing the techniques of Numerical Integration.pdfOverviewing the techniques of Numerical Integration.pdf
Overviewing the techniques of Numerical Integration.pdf
 
Motorola 68020.pdf
Motorola 68020.pdfMotorola 68020.pdf
Motorola 68020.pdf
 
Stereotactic Radiosurgery in Brain Metastases.pdf
Stereotactic Radiosurgery in Brain Metastases.pdfStereotactic Radiosurgery in Brain Metastases.pdf
Stereotactic Radiosurgery in Brain Metastases.pdf
 
Active Filters.pdf
Active Filters.pdfActive Filters.pdf
Active Filters.pdf
 
Wideband Frequency Modulation.pdf
Wideband Frequency Modulation.pdfWideband Frequency Modulation.pdf
Wideband Frequency Modulation.pdf
 
Celebrity Problem.pdf
Celebrity Problem.pdfCelebrity Problem.pdf
Celebrity Problem.pdf
 
SSBSC Single Side Band - Suppressed Carrier Compressed
SSBSC Single Side Band - Suppressed Carrier CompressedSSBSC Single Side Band - Suppressed Carrier Compressed
SSBSC Single Side Band - Suppressed Carrier Compressed
 
Biodiversity Hotspots in India
Biodiversity Hotspots in IndiaBiodiversity Hotspots in India
Biodiversity Hotspots in India
 
LTI Systems - With/Without Memory
LTI Systems - With/Without MemoryLTI Systems - With/Without Memory
LTI Systems - With/Without Memory
 
RLC Series Resonance
RLC Series ResonanceRLC Series Resonance
RLC Series Resonance
 
Bivariate Discrete Distribution
Bivariate Discrete DistributionBivariate Discrete Distribution
Bivariate Discrete Distribution
 
Solar Cell
Solar CellSolar Cell
Solar Cell
 
Barcode Decoder
Barcode DecoderBarcode Decoder
Barcode Decoder
 
Dijkstra's Algorithm
Dijkstra's AlgorithmDijkstra's Algorithm
Dijkstra's Algorithm
 
Conditional Probability
Conditional ProbabilityConditional Probability
Conditional Probability
 
Isomerism of Transition Metal Complex
Isomerism of Transition Metal ComplexIsomerism of Transition Metal Complex
Isomerism of Transition Metal Complex
 
Space Solar Power
Space Solar PowerSpace Solar Power
Space Solar Power
 
Power Series - Legendre Polynomial - Bessel's Equation
Power Series - Legendre Polynomial - Bessel's EquationPower Series - Legendre Polynomial - Bessel's Equation
Power Series - Legendre Polynomial - Bessel's Equation
 

Recently uploaded

Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
MuhammadTufail242431
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
Kamal Acharya
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 

Recently uploaded (20)

Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 

Types of function call

  • 1. Function Call by Value & Reference By: Arijit Dhali
  • 2. Contents 2 User Defined Function Common Method of Swapping Integers Call by Value Call by Reference Differences Conclusion
  • 3. User Defined Function A user-defined function is a function provided by the user of a program or environment, in a context where the usual assumption is that functions are built into the program or environment. Syntax: return_type function_name (parameter list) { Function Body return statement; } 3
  • 4. Common Method of Swapping Two Integers 4 #include<stdio.h> main() { int x, y, z; printf (“n Enter the value of x: "); scanf ("%d", &x); printf (“n Enter the value of y: "); scanf ("%d", &y); z = x; x = y; y = z; printf ( "n After swap : x = %d, y = %d n", x, y); return 0; } Using Third Variable Source Code: Storing Value Storing Value Swap using 3rd Variable Declaring Variable
  • 6. 6 Call by Value The call by value method of passing argument to a function, copies the actual value of an argument into the formal parameter of the function. In this case, changed made to parameter inside the function had no effect on argument.
  • 7. 7 #include<stdio.h> void swapvalue(int x,int y); int main() { int a,b; printf(“n Enter two numbers: "); scanf("%d %d",&a,&b); printf(“n Before Swapping a=%d, b=%d n",a,b); swapvalue(a,b); printf(“n After Swapping a=%d, b=%d n",a,b); return 0; } void swapvalue(int x,int y) { int temp; temp=x; x=y; y=temp; return; } Source Code: Swap using 3rd Variable Function Definition Function Declaration Declaring Variable Function Calling Passing Variable
  • 9. 9 Call by Reference The Call by Reference method of passing arguments to a function copies the address of an argument into the formal parameter. Inside the function, the address is used to access the actual argument used in the call. This means that changes made to be parameter affect the passed argument. To pass the value by reference, argument pointers are passed to the functions just like any other value. So, accordingly you need to declare the function parameters as pointer types as in the following swap(), which exchanges the values of the two integer variables pointed to by its arguments.
  • 10. 10 #include<stdio.h> void swapreference(int *x,int *y); int main() { int a,b; printf(“n Enter two numbers: "); scanf("%d %d",&a,&b); printf(“n Before Swapping a=%d, b=%d",a,b); swapreference(&a,&b); printf(“n After Swapping a=%d, b=%d",a,b); return 0; } void swapreference(int *x, int *y) { int temp=0; temp=*x; *x=*y; *y=temp; return; } Source Code: Swapping address using 3rd Variable Function Calling Passing Address Function Definition along with defining Pointer Function Declaration Declaring Variable
  • 12. › The function is called by directly passing value of variable as argument. › We need to declare a general variable as function argument. › Changes made in the formal parameters will not be reflected in the actual parameters. It is because formal and actual parameters are stored in different locations. Call by Value v/s Call by Reference › The function is called by directly passing address of variable as argument. › We need to declare pointer variable as function argument. › Changes made in the formal parameters will be reflected in the actual parameters. It is because formal and actual parameters are stored in same locations. 12 Call by Value Call by Reference
  • 13. 13 Conclusion As the Conclusion , If we want to pass only the value of variable use ‘call by value’ approach, and if you want to see the change in the original value of the variable then use ‘call by reference’ approach.
  • 14. GRACIAS 14 Hope to see you again!!!