SlideShare a Scribd company logo
Lecture 14Lecture 14
Version 1.0Version 1.0
Call by ReferenceCall by Reference
2Rushdi Shams, Dept of CSE, KUET, Bangladesh
Methods to pass argumentsMethods to pass arguments
 Arguments can generally be passed to functionsArguments can generally be passed to functions
in one of the two ways:in one of the two ways:
(a) sending the values of the arguments(a) sending the values of the arguments
(b) sending the addresses of the arguments(b) sending the addresses of the arguments
3Rushdi Shams, Dept of CSE, KUET, Bangladesh
Call by valueCall by value
 ‘‘value’ of each of the actual arguments in thevalue’ of each of the actual arguments in the
calling function is copied into correspondingcalling function is copied into corresponding
formal arguments of the called functionformal arguments of the called function
 changes made to the formal arguments in thechanges made to the formal arguments in the
called function have no effect on the values ofcalled function have no effect on the values of
actual arguments in the calling functionactual arguments in the calling function
4Rushdi Shams, Dept of CSE, KUET, Bangladesh
Call by valueCall by value
5Rushdi Shams, Dept of CSE, KUET, Bangladesh
Call by ReferenceCall by Reference
 the addresses of actual arguments in the callingthe addresses of actual arguments in the calling
function are copied into formal arguments offunction are copied into formal arguments of
the called functionthe called function
 using these addresses we would have an accessusing these addresses we would have an access
to the actual arguments and hence we would beto the actual arguments and hence we would be
able to manipulate themable to manipulate them
6Rushdi Shams, Dept of CSE, KUET, Bangladesh
Call by ReferenceCall by Reference
a
10
65000
b
20
60000
x
65000
70000
y
60000
75000
t
10
80000
20 10
7Rushdi Shams, Dept of CSE, KUET, Bangladesh
Call by referenceCall by reference
 Using a call by reference intelligently we canUsing a call by reference intelligently we can
make a function return more than one value at amake a function return more than one value at a
time, which is not possible ordinarilytime, which is not possible ordinarily
8Rushdi Shams, Dept of CSE, KUET, Bangladesh
Call by referenceCall by reference
9Rushdi Shams, Dept of CSE, KUET, Bangladesh
What is the output?What is the output?
10Rushdi Shams, Dept of CSE, KUET, Bangladesh
What will be the output?What will be the output?
11Rushdi Shams, Dept of CSE, KUET, Bangladesh
What will be the output?What will be the output?
12Rushdi Shams, Dept of CSE, KUET, Bangladesh
What will be the output?What will be the output?

More Related Content

Similar to Lec 14. Call by Reference

Lec 10. Functions (Part II)
Lec 10. Functions (Part II)Lec 10. Functions (Part II)
Lec 10. Functions (Part II)
Rushdi Shams
 
Lec 15. Pointers and Arrays
Lec 15. Pointers and ArraysLec 15. Pointers and Arrays
Lec 15. Pointers and Arrays
Rushdi Shams
 
Lec 12. Multidimensional Arrays / Passing Arrays to Functions
Lec 12. Multidimensional Arrays / Passing Arrays to FunctionsLec 12. Multidimensional Arrays / Passing Arrays to Functions
Lec 12. Multidimensional Arrays / Passing Arrays to Functions
Rushdi Shams
 
Lec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by ValuesLec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by Values
Rushdi Shams
 
Lec 13. Introduction to Pointers
Lec 13. Introduction to PointersLec 13. Introduction to Pointers
Lec 13. Introduction to Pointers
Rushdi Shams
 

Similar to Lec 14. Call by Reference (6)

Lec 10. Functions (Part II)
Lec 10. Functions (Part II)Lec 10. Functions (Part II)
Lec 10. Functions (Part II)
 
Lec 15. Pointers and Arrays
Lec 15. Pointers and ArraysLec 15. Pointers and Arrays
Lec 15. Pointers and Arrays
 
Lec 12. Multidimensional Arrays / Passing Arrays to Functions
Lec 12. Multidimensional Arrays / Passing Arrays to FunctionsLec 12. Multidimensional Arrays / Passing Arrays to Functions
Lec 12. Multidimensional Arrays / Passing Arrays to Functions
 
Lec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by ValuesLec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by Values
 
Lec 13. Introduction to Pointers
Lec 13. Introduction to PointersLec 13. Introduction to Pointers
Lec 13. Introduction to Pointers
 
Rasa Developer Summit - Josh Converse, Dynamic Offset - Three Part Harmony: H...
Rasa Developer Summit - Josh Converse, Dynamic Offset - Three Part Harmony: H...Rasa Developer Summit - Josh Converse, Dynamic Offset - Three Part Harmony: H...
Rasa Developer Summit - Josh Converse, Dynamic Offset - Three Part Harmony: H...
 

More from Rushdi Shams

Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
Rushdi Shams
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
Rushdi Shams
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
Rushdi Shams
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
Rushdi Shams
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
Rushdi Shams
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
Rushdi Shams
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
Rushdi Shams
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
Rushdi Shams
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
Rushdi Shams
 
L2 l3 l4 software process models
L2 l3 l4  software process modelsL2 l3 l4  software process models
L2 l3 l4 software process models
Rushdi Shams
 

More from Rushdi Shams (20)

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better Research
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IR
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processing
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
 
L15 fuzzy logic
L15  fuzzy logicL15  fuzzy logic
L15 fuzzy logic
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
First order logic
First order logicFirst order logic
First order logic
 
Belief function
Belief functionBelief function
Belief function
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
 
L4 vpn
L4  vpnL4  vpn
L4 vpn
 
L3 defense
L3  defenseL3  defense
L3 defense
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
 
L2 l3 l4 software process models
L2 l3 l4  software process modelsL2 l3 l4  software process models
L2 l3 l4 software process models
 

Recently uploaded

Recently uploaded (20)

The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
NLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxNLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Forest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDFForest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDF
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation
 

Lec 14. Call by Reference

  • 1. Lecture 14Lecture 14 Version 1.0Version 1.0 Call by ReferenceCall by Reference
  • 2. 2Rushdi Shams, Dept of CSE, KUET, Bangladesh Methods to pass argumentsMethods to pass arguments  Arguments can generally be passed to functionsArguments can generally be passed to functions in one of the two ways:in one of the two ways: (a) sending the values of the arguments(a) sending the values of the arguments (b) sending the addresses of the arguments(b) sending the addresses of the arguments
  • 3. 3Rushdi Shams, Dept of CSE, KUET, Bangladesh Call by valueCall by value  ‘‘value’ of each of the actual arguments in thevalue’ of each of the actual arguments in the calling function is copied into correspondingcalling function is copied into corresponding formal arguments of the called functionformal arguments of the called function  changes made to the formal arguments in thechanges made to the formal arguments in the called function have no effect on the values ofcalled function have no effect on the values of actual arguments in the calling functionactual arguments in the calling function
  • 4. 4Rushdi Shams, Dept of CSE, KUET, Bangladesh Call by valueCall by value
  • 5. 5Rushdi Shams, Dept of CSE, KUET, Bangladesh Call by ReferenceCall by Reference  the addresses of actual arguments in the callingthe addresses of actual arguments in the calling function are copied into formal arguments offunction are copied into formal arguments of the called functionthe called function  using these addresses we would have an accessusing these addresses we would have an access to the actual arguments and hence we would beto the actual arguments and hence we would be able to manipulate themable to manipulate them
  • 6. 6Rushdi Shams, Dept of CSE, KUET, Bangladesh Call by ReferenceCall by Reference a 10 65000 b 20 60000 x 65000 70000 y 60000 75000 t 10 80000 20 10
  • 7. 7Rushdi Shams, Dept of CSE, KUET, Bangladesh Call by referenceCall by reference  Using a call by reference intelligently we canUsing a call by reference intelligently we can make a function return more than one value at amake a function return more than one value at a time, which is not possible ordinarilytime, which is not possible ordinarily
  • 8. 8Rushdi Shams, Dept of CSE, KUET, Bangladesh Call by referenceCall by reference
  • 9. 9Rushdi Shams, Dept of CSE, KUET, Bangladesh What is the output?What is the output?
  • 10. 10Rushdi Shams, Dept of CSE, KUET, Bangladesh What will be the output?What will be the output?
  • 11. 11Rushdi Shams, Dept of CSE, KUET, Bangladesh What will be the output?What will be the output?
  • 12. 12Rushdi Shams, Dept of CSE, KUET, Bangladesh What will be the output?What will be the output?