SlideShare a Scribd company logo
References are "Nice" Pointers
void moveBall(ball &b)
{
b.x += 5;
}
int main()
{
ball b;
b.x = 10;
b.y = 20;
moveBall(b);
return 0;
}
struct ball
{
int x;
int y;
};
We previously saw pass-
by-reference like this…
References are "Nice" Pointers
void moveBall(ball *b)
{
(*b).x += 5;
}
int main()
{
ball b;
b.x = 10;
b.y = 20;
moveBall(&b);
return 0;
}
…but references are just
nice ways of using
pointers.
struct ball
{
int x;
int y;
};
References are "Nice" Pointers
void moveBall(ball *b)
{
b->x += 5;
}
int main()
{
ball b;
b.x = 10;
b.y = 20;
moveBall(&b);
return 0;
}
Instead of dereferencing
with *, then getting a
member attribute with .,
you can use ->
struct ball
{
int x;
int y;
};

More Related Content

PPTX
Presentation for structure in c
PDF
Pointers
PDF
Function Call Stack
PDF
Head and Tail Recursion
PDF
Branching Story Example
PDF
Deep Copy of a Linked List
PDF
Linked List Operations
PDF
Insertion Sort Algorithm
Presentation for structure in c
Pointers
Function Call Stack
Head and Tail Recursion
Branching Story Example
Deep Copy of a Linked List
Linked List Operations
Insertion Sort Algorithm

More from Gail Carmichael (9)

PDF
Find the Maximum Algorithm
PDF
Attracting Women to Computing and Why it Matters
PDF
Thesis Proposal: Creating Satisfying Game Experiences with Coherent Emergent ...
PDF
Interactive Storytelling in Games: Next Steps
PDF
Coherent Emergent Stories - GHC13
PDF
Interactive Storytelling (CUSEC 2013)
PPTX
Understanding the Power of Augmented Reality for Learning
PPTX
Interactive Storytelling (CANCON 2012)
PPTX
Global Context Descriptors for SURF and MSER Feature Descriptors
Find the Maximum Algorithm
Attracting Women to Computing and Why it Matters
Thesis Proposal: Creating Satisfying Game Experiences with Coherent Emergent ...
Interactive Storytelling in Games: Next Steps
Coherent Emergent Stories - GHC13
Interactive Storytelling (CUSEC 2013)
Understanding the Power of Augmented Reality for Learning
Interactive Storytelling (CANCON 2012)
Global Context Descriptors for SURF and MSER Feature Descriptors
Ad

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Cloud computing and distributed systems.
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
cuic standard and advanced reporting.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Big Data Technologies - Introduction.pptx
PDF
Encapsulation theory and applications.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Approach and Philosophy of On baking technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPT
Teaching material agriculture food technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
Cloud computing and distributed systems.
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Network Security Unit 5.pdf for BCA BBA.
Building Integrated photovoltaic BIPV_UPV.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
MIND Revenue Release Quarter 2 2025 Press Release
cuic standard and advanced reporting.pdf
Unlocking AI with Model Context Protocol (MCP)
MYSQL Presentation for SQL database connectivity
Big Data Technologies - Introduction.pptx
Encapsulation theory and applications.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Empathic Computing: Creating Shared Understanding
Approach and Philosophy of On baking technology
Review of recent advances in non-invasive hemoglobin estimation
Teaching material agriculture food technology
Ad

References Are 'Nice' Pointers

  • 1. References are "Nice" Pointers void moveBall(ball &b) { b.x += 5; } int main() { ball b; b.x = 10; b.y = 20; moveBall(b); return 0; } struct ball { int x; int y; }; We previously saw pass- by-reference like this…
  • 2. References are "Nice" Pointers void moveBall(ball *b) { (*b).x += 5; } int main() { ball b; b.x = 10; b.y = 20; moveBall(&b); return 0; } …but references are just nice ways of using pointers. struct ball { int x; int y; };
  • 3. References are "Nice" Pointers void moveBall(ball *b) { b->x += 5; } int main() { ball b; b.x = 10; b.y = 20; moveBall(&b); return 0; } Instead of dereferencing with *, then getting a member attribute with ., you can use -> struct ball { int x; int y; };