SlideShare a Scribd company logo
2
Most read
4
Most read
5
Most read
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)

More Related Content

What's hot (20)

PPTX
User defined functions in C
Harendra Singh
 
PPSX
Files in c++
Selvin Josy Bai Somu
 
PPTX
Functions in c++
Rokonuzzaman Rony
 
PPTX
Java exception handling
BHUVIJAYAVELU
 
PPTX
Inline function
Tech_MX
 
PDF
Classes and objects
Nilesh Dalvi
 
PPSX
Data Types & Variables in JAVA
Ankita Totala
 
PPT
friend function(c++)
Ritika Sharma
 
PPTX
Nested loops
Neeru Mittal
 
PDF
Operator overloading
Pranali Chaudhari
 
PPT
Function overloading(c++)
Ritika Sharma
 
PPTX
C functions
University of Potsdam
 
PDF
Functions in C++
Pranali Chaudhari
 
PPT
Input and output in C++
Nilesh Dalvi
 
PPTX
Looping Statements and Control Statements in Python
PriyankaC44
 
PDF
Exception handling
Pranali Chaudhari
 
PPTX
data types in C programming
Harshita Yadav
 
PPT
Introduction to method overloading & method overriding in java hdm
Harshal Misalkar
 
PDF
Datatypes in python
eShikshak
 
PPTX
Function C programming
Appili Vamsi Krishna
 
User defined functions in C
Harendra Singh
 
Files in c++
Selvin Josy Bai Somu
 
Functions in c++
Rokonuzzaman Rony
 
Java exception handling
BHUVIJAYAVELU
 
Inline function
Tech_MX
 
Classes and objects
Nilesh Dalvi
 
Data Types & Variables in JAVA
Ankita Totala
 
friend function(c++)
Ritika Sharma
 
Nested loops
Neeru Mittal
 
Operator overloading
Pranali Chaudhari
 
Function overloading(c++)
Ritika Sharma
 
Functions in C++
Pranali Chaudhari
 
Input and output in C++
Nilesh Dalvi
 
Looping Statements and Control Statements in Python
PriyankaC44
 
Exception handling
Pranali Chaudhari
 
data types in C programming
Harshita Yadav
 
Introduction to method overloading & method overriding in java hdm
Harshal Misalkar
 
Datatypes in python
eShikshak
 
Function C programming
Appili Vamsi Krishna
 

Viewers also liked (9)

PDF
Information About Wild Life
Arunkumar Kholkute
 
PPT
Natural vegetation & wild life
Niharika Pande
 
PPS
Great Animals And Birds
islamtics default
 
PPTX
ENDANGERED AND ENDEMIC SPECIES
Meera Amutha
 
PPTX
Endangered species of india
CVVMMK Dhaveji
 
PPTX
Wildlife conservation in India(ppt)
utkarshs92
 
PPTX
extinct animal and birds
Ravi Rajput
 
PPTX
Endangered Species & Extinction
zpearson
 
PPTX
Endangered species powerpoint
mrstadams22
 
Information About Wild Life
Arunkumar Kholkute
 
Natural vegetation & wild life
Niharika Pande
 
Great Animals And Birds
islamtics default
 
ENDANGERED AND ENDEMIC SPECIES
Meera Amutha
 
Endangered species of india
CVVMMK Dhaveji
 
Wildlife conservation in India(ppt)
utkarshs92
 
extinct animal and birds
Ravi Rajput
 
Endangered Species & Extinction
zpearson
 
Endangered species powerpoint
mrstadams22
 
Ad

Similar to Pass by value and pass by reference (20)

PPTX
a brief explanation on the topic of Imperative Programming Paradigm.pptx
sajit20
 
PPTX
Java-Intro.pptx
VijalJain3
 
KEY
Learning from "Effective Scala"
Kazuhiro Sera
 
PPTX
Introduction to oop and java fundamentals
AnsgarMary
 
PPTX
Java Serialization Facts and Fallacies
Roman Elizarov
 
PDF
Difference between java and c#
TECOS
 
PPTX
Code reviews
Roger Xia
 
PDF
Swift language - A fast overview of some features
Weverton Timoteo
 
PPTX
Java and the JVM
Manish Pandit
 
PPTX
TypeScript Overview
Aniruddha Chakrabarti
 
PPTX
U-SQL - Azure Data Lake Analytics for Developers
Michael Rys
 
PDF
Typesafe stack - Scala, Akka and Play
Luka Zakrajšek
 
PPTX
Scala, Play 2.0 & Cloud Foundry
Pray Desai
 
PPTX
Iterator - a powerful but underappreciated design pattern
Nitin Bhide
 
PDF
BoxLang JVM Language : The Future is Dynamic
Ortus Solutions, Corp
 
PDF
High Performance Systems in Go - GopherCon 2014
Derek Collison
 
PPT
Java OOP s concepts and buzzwords
Raja Sekhar
 
a brief explanation on the topic of Imperative Programming Paradigm.pptx
sajit20
 
Java-Intro.pptx
VijalJain3
 
Learning from "Effective Scala"
Kazuhiro Sera
 
Introduction to oop and java fundamentals
AnsgarMary
 
Java Serialization Facts and Fallacies
Roman Elizarov
 
Difference between java and c#
TECOS
 
Code reviews
Roger Xia
 
Swift language - A fast overview of some features
Weverton Timoteo
 
Java and the JVM
Manish Pandit
 
TypeScript Overview
Aniruddha Chakrabarti
 
U-SQL - Azure Data Lake Analytics for Developers
Michael Rys
 
Typesafe stack - Scala, Akka and Play
Luka Zakrajšek
 
Scala, Play 2.0 & Cloud Foundry
Pray Desai
 
Iterator - a powerful but underappreciated design pattern
Nitin Bhide
 
BoxLang JVM Language : The Future is Dynamic
Ortus Solutions, Corp
 
High Performance Systems in Go - GopherCon 2014
Derek Collison
 
Java OOP s concepts and buzzwords
Raja Sekhar
 
Ad

More from TurnToTech (8)

PDF
Why Mobile is driving eCommerce
TurnToTech
 
PPTX
Beginning iOS Development with Swift
TurnToTech
 
PPTX
Tech Interview Job Prep
TurnToTech
 
PPTX
noSQL
TurnToTech
 
PPTX
Strings and common operations
TurnToTech
 
PPTX
Numbers
TurnToTech
 
PDF
What's new in iOS 10 for developers?
TurnToTech
 
PDF
Web Development Presentation
TurnToTech
 
Why Mobile is driving eCommerce
TurnToTech
 
Beginning iOS Development with Swift
TurnToTech
 
Tech Interview Job Prep
TurnToTech
 
noSQL
TurnToTech
 
Strings and common operations
TurnToTech
 
Numbers
TurnToTech
 
What's new in iOS 10 for developers?
TurnToTech
 
Web Development Presentation
TurnToTech
 

Recently uploaded (20)

PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 

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)