SlideShare uma empresa Scribd logo
1 de 8
Pass by value and
pass by reference
Example
Example 2
website
Pass by value
• Creates a copy of the value when passed to a function
• Better in multi-threaded environment
• Required in distributed and remote systems.
• Simple memory management
• In some implementations, takes less memory than reference
types because there is no pointer, inherited properties.
• Some languages reduce memory overhead of copies by using
copy-on-write (Swift)
Pass by reference
• No copying of data (only creation of a pointer) which
can means less memory
• Many functions/classes can share a single object
• Memory must be managed (reference counting or
garbage collection)
• Can cause problems with multithreading
• Can return ‘multiple values’ from a function
Value types
Java PrimitiveType (NumericType and boolean)
Booleans, integers and floats (of their various widths)
*broad generalization
Objective-C C scalars (int, float, char)
Objective-C scalars (NSInteger, CGFloat, BOOL)
C structures (NSRange, CLLocationCoordinate2D)
Swift Almost all built-in types including Dictionary, Array and String.
In Swift 2, 87 of 99 types are value types.
Reference Types
Java Anything that inherits from Object
Objective-C Anything that inherits from NSObject
Swift Classes
Note:
• In Java, references to object are passed by value (e.g.
a new reference is created when passed)

Mais conteúdo relacionado

Mais procurados

Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
Alok Kumar
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
Vasavi College of Engg
 

Mais procurados (20)

Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Namespaces
NamespacesNamespaces
Namespaces
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programming
 
JVM
JVMJVM
JVM
 
Java basics and java variables
Java basics and java variablesJava basics and java variables
Java basics and java variables
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_c
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Java keywords
Java keywordsJava keywords
Java keywords
 
Constructor
ConstructorConstructor
Constructor
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
 
Interface in java
Interface in javaInterface in java
Interface in java
 

Destaque (9)

Information About Wild Life
Information About Wild LifeInformation About Wild Life
Information About Wild Life
 
Natural vegetation & wild life
Natural vegetation & wild lifeNatural vegetation & wild life
Natural vegetation & wild life
 
Great Animals And Birds
Great Animals And BirdsGreat Animals And Birds
Great Animals And Birds
 
ENDANGERED AND ENDEMIC SPECIES
ENDANGERED AND ENDEMIC SPECIESENDANGERED AND ENDEMIC SPECIES
ENDANGERED AND ENDEMIC SPECIES
 
Endangered species of india
Endangered species of india Endangered species of india
Endangered species of india
 
Wildlife conservation in India(ppt)
Wildlife conservation in India(ppt)Wildlife conservation in India(ppt)
Wildlife conservation in India(ppt)
 
extinct animal and birds
extinct animal and birdsextinct animal and birds
extinct animal and birds
 
Endangered Species & Extinction
Endangered Species & ExtinctionEndangered Species & Extinction
Endangered Species & Extinction
 
Endangered species powerpoint
Endangered species powerpointEndangered species powerpoint
Endangered species powerpoint
 

Semelhante a Pass by value and pass by reference

Java Serialization Facts and Fallacies
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and Fallacies
Roman Elizarov
 
Code reviews
Code reviewsCode reviews
Code reviews
Roger Xia
 
Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and Play
Luka Zakrajšek
 

Semelhante a Pass by value and pass by reference (20)

Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
Learning from "Effective Scala"
Learning from "Effective Scala"Learning from "Effective Scala"
Learning from "Effective Scala"
 
Php
PhpPhp
Php
 
Php
PhpPhp
Php
 
Php
PhpPhp
Php
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentalsIntroduction to oop and java fundamentals
Introduction to oop and java fundamentals
 
Java Serialization Facts and Fallacies
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and Fallacies
 
Difference between java and c#
Difference between java and c#Difference between java and c#
Difference between java and c#
 
Code reviews
Code reviewsCode reviews
Code reviews
 
Swift language - A fast overview of some features
Swift language - A fast overview of some featuresSwift language - A fast overview of some features
Swift language - A fast overview of some features
 
Java and the JVM
Java and the JVMJava and the JVM
Java and the JVM
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
U-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for DevelopersU-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for Developers
 
Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and Play
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design pattern
 
High Performance Systems in Go - GopherCon 2014
High Performance Systems in Go - GopherCon 2014High Performance Systems in Go - GopherCon 2014
High Performance Systems in Go - GopherCon 2014
 
Java OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsJava OOP s concepts and buzzwords
Java OOP s concepts and buzzwords
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
DSL's with Groovy
DSL's with GroovyDSL's with Groovy
DSL's with Groovy
 

Mais de TurnToTech (8)

Why Mobile is driving eCommerce
Why Mobile is driving eCommerceWhy Mobile is driving eCommerce
Why Mobile is driving eCommerce
 
Beginning iOS Development with Swift
Beginning iOS Development with SwiftBeginning iOS Development with Swift
Beginning iOS Development with Swift
 
Tech Interview Job Prep
Tech Interview Job PrepTech Interview Job Prep
Tech Interview Job Prep
 
noSQL
noSQLnoSQL
noSQL
 
Strings and common operations
Strings and common operationsStrings and common operations
Strings and common operations
 
Numbers
NumbersNumbers
Numbers
 
What's new in iOS 10 for developers?
What's new in iOS 10 for developers?What's new in iOS 10 for developers?
What's new in iOS 10 for developers?
 
Web Development Presentation
Web Development PresentationWeb Development Presentation
Web Development Presentation
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 

Pass by value and pass by reference

  • 1. Pass by value and pass by reference
  • 4. Pass by value • Creates a copy of the value when passed to a function • Better in multi-threaded environment • Required in distributed and remote systems. • Simple memory management • In some implementations, takes less memory than reference types because there is no pointer, inherited properties. • Some languages reduce memory overhead of copies by using copy-on-write (Swift)
  • 5. Pass by reference • No copying of data (only creation of a pointer) which can means less memory • Many functions/classes can share a single object • Memory must be managed (reference counting or garbage collection) • Can cause problems with multithreading • Can return ‘multiple values’ from a function
  • 6. Value types Java PrimitiveType (NumericType and boolean) Booleans, integers and floats (of their various widths) *broad generalization Objective-C C scalars (int, float, char) Objective-C scalars (NSInteger, CGFloat, BOOL) C structures (NSRange, CLLocationCoordinate2D) Swift Almost all built-in types including Dictionary, Array and String. In Swift 2, 87 of 99 types are value types.
  • 7. Reference Types Java Anything that inherits from Object Objective-C Anything that inherits from NSObject Swift Classes
  • 8. Note: • In Java, references to object are passed by value (e.g. a new reference is created when passed)