SlideShare a Scribd company logo
Chapter-7 Pointers
Pointers ,[object Object],[object Object],[object Object],[object Object],[object Object]
Pointers Variable in memory 1000 1001 1002 1003 1004 1005 1006 103 Memory address
The ‘&’ and ‘*’ ,[object Object],[object Object],[object Object],[object Object],[object Object]
The ‘&’ and ‘*’ 3 ab 1000 Location name Value at Location Address
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The ‘&’ and ‘*’ ,[object Object],[object Object],[object Object],[object Object]
An Example:Pointers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Output: Address of j = 1000 Value of j = 5 Value of j = 5
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],A program that prints out pointers and the values they point to:
Write a program that computes the area and perimeter of a rectangle: #include <stdio.h> void rectangle(int a, int b, int  * area, int  * perim); int main() { int x, y; int area, perim; printf(&quot;Enter two values separated by space: &quot; ); scanf(&quot;%d %d&quot;, &x, &y); rectangle(x, y, &area, &perim); printf(&quot;Area is %d Perimeter is %d&quot;, area, perim); return 0; } void rectangle(int a,int b,int  * area,int  * perim) { *area = a * b; *perim = 2 * (a + b); }
Pointer Expressions ,[object Object],[object Object],[object Object],[object Object],[object Object]
Pointer Assignments ,[object Object],Here i’s value is 5 and j’s value is i’s address. i 5 1000 1000 2000 j
Pointer Assignments ,[object Object],[object Object]
An Example:Pointer Assignments ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Output: Address of j = 1000 Address of j = 1000 Address of k = 2000 Value of k = 1000 Value of j = 3 Value of j = 3 Value of j = error
Pointer Conversions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Pointers v/s Arrays ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Output: Embedded Embedded
Pointers v/s Arrays ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Analysis: Pointers v/s Arrays ,[object Object],[object Object]
Arrays of Pointers ,[object Object],[object Object]
An Example: Arrays of Pointers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Arrays of Pointers 1000 2500 2000 1500 i 5 10 j 20 15 l k 2500 2000 1500 1000 arr[0] arr[3] arr[2] arr[1] 1200 2700 2200 1700
Pointers To Pointers ,[object Object],[object Object]
Double Pointers 3 i 1000 1000 2000 j 2000 3000 k
Double Pointer ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Double Pointer OUTPUT: Address of i is 1000 1000 1000 Address of j is 2000 2000 Address of k is 3000  Value of i is 3 3 3 3 Value of j is 1000 Value of k is 2000
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

9. pointer, pointer & function
9. pointer, pointer & function9. pointer, pointer & function
9. pointer, pointer & function
웅식 전
 
CSE240 Macros and Preprocessing
CSE240 Macros and PreprocessingCSE240 Macros and Preprocessing
CSE240 Macros and Preprocessing
Garrett Gutierrez
 
10. array & pointer
10. array & pointer10. array & pointer
10. array & pointer
웅식 전
 

What's hot (20)

C programming pointer
C  programming pointerC  programming pointer
C programming pointer
 
SPC Unit 3
SPC Unit 3SPC Unit 3
SPC Unit 3
 
9. pointer, pointer & function
9. pointer, pointer & function9. pointer, pointer & function
9. pointer, pointer & function
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Ponters
PontersPonters
Ponters
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
CSE240 Macros and Preprocessing
CSE240 Macros and PreprocessingCSE240 Macros and Preprocessing
CSE240 Macros and Preprocessing
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c language
 
C pointer basics
C pointer basicsC pointer basics
C pointer basics
 
10. array & pointer
10. array & pointer10. array & pointer
10. array & pointer
 
pointers
pointerspointers
pointers
 
Data structure week 3
Data structure week 3Data structure week 3
Data structure week 3
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in c
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
 
C Pointers
C PointersC Pointers
C Pointers
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Module 02 Pointers in C
Module 02 Pointers in CModule 02 Pointers in C
Module 02 Pointers in C
 

Viewers also liked

Social Networking in the Business World: A Strategic Approach
Social Networking in the Business World: A Strategic ApproachSocial Networking in the Business World: A Strategic Approach
Social Networking in the Business World: A Strategic Approach
linkedinlion11
 
Medical Terminology
Medical TerminologyMedical Terminology
Medical Terminology
gnaz786
 
Donald Clark Citizens And Netizens Weapons Of Mass Collaboration
Donald Clark   Citizens And Netizens Weapons Of Mass CollaborationDonald Clark   Citizens And Netizens Weapons Of Mass Collaboration
Donald Clark Citizens And Netizens Weapons Of Mass Collaboration
JMHarkin
 

Viewers also liked (8)

Projectrapport
ProjectrapportProjectrapport
Projectrapport
 
Lan texto
Lan textoLan texto
Lan texto
 
Social Networking in the Business World: A Strategic Approach
Social Networking in the Business World: A Strategic ApproachSocial Networking in the Business World: A Strategic Approach
Social Networking in the Business World: A Strategic Approach
 
Blog profissional
Blog profissionalBlog profissional
Blog profissional
 
Medical Terminology
Medical TerminologyMedical Terminology
Medical Terminology
 
Tesj008
Tesj008Tesj008
Tesj008
 
Marketing
MarketingMarketing
Marketing
 
Donald Clark Citizens And Netizens Weapons Of Mass Collaboration
Donald Clark   Citizens And Netizens Weapons Of Mass CollaborationDonald Clark   Citizens And Netizens Weapons Of Mass Collaboration
Donald Clark Citizens And Netizens Weapons Of Mass Collaboration
 

Similar to Ch 7-pointers

Chapter 13.1.8
Chapter 13.1.8Chapter 13.1.8
Chapter 13.1.8
patcha535
 

Similar to Ch 7-pointers (20)

C pointers and references
C pointers and referencesC pointers and references
C pointers and references
 
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdfEASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
 
[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to Pointers[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to Pointers
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
Unit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptxUnit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptx
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
iit c prog.ppt
iit c prog.pptiit c prog.ppt
iit c prog.ppt
 
Chapter5.pptx
Chapter5.pptxChapter5.pptx
Chapter5.pptx
 
VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3
 
Chapter 13.1.8
Chapter 13.1.8Chapter 13.1.8
Chapter 13.1.8
 
Ponters
PontersPonters
Ponters
 
Unit 6 pointers
Unit 6   pointersUnit 6   pointers
Unit 6 pointers
 
PSPC--UNIT-5.pdf
PSPC--UNIT-5.pdfPSPC--UNIT-5.pdf
PSPC--UNIT-5.pdf
 
Lk module5 pointers
Lk module5 pointersLk module5 pointers
Lk module5 pointers
 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programming
 
Pointers.pptx
Pointers.pptxPointers.pptx
Pointers.pptx
 
Pointers in c++ by minal
Pointers in c++ by minalPointers in c++ by minal
Pointers in c++ by minal
 
4 Pointers.pptx
4 Pointers.pptx4 Pointers.pptx
4 Pointers.pptx
 
Engineering Computers L32-L33-Pointers.pptx
Engineering Computers L32-L33-Pointers.pptxEngineering Computers L32-L33-Pointers.pptx
Engineering Computers L32-L33-Pointers.pptx
 
Pointers.pdf
Pointers.pdfPointers.pdf
Pointers.pdf
 

Recently uploaded

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Recently uploaded (20)

Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Agentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfAgentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdf
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
The architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdfThe architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 

Ch 7-pointers

  • 2.
  • 3. Pointers Variable in memory 1000 1001 1002 1003 1004 1005 1006 103 Memory address
  • 4.
  • 5. The ‘&’ and ‘*’ 3 ab 1000 Location name Value at Location Address
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. Write a program that computes the area and perimeter of a rectangle: #include <stdio.h> void rectangle(int a, int b, int * area, int * perim); int main() { int x, y; int area, perim; printf(&quot;Enter two values separated by space: &quot; ); scanf(&quot;%d %d&quot;, &x, &y); rectangle(x, y, &area, &perim); printf(&quot;Area is %d Perimeter is %d&quot;, area, perim); return 0; } void rectangle(int a,int b,int * area,int * perim) { *area = a * b; *perim = 2 * (a + b); }
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21. Arrays of Pointers 1000 2500 2000 1500 i 5 10 j 20 15 l k 2500 2000 1500 1000 arr[0] arr[3] arr[2] arr[1] 1200 2700 2200 1700
  • 22.
  • 23. Double Pointers 3 i 1000 1000 2000 j 2000 3000 k
  • 24.
  • 25. Double Pointer OUTPUT: Address of i is 1000 1000 1000 Address of j is 2000 2000 Address of k is 3000 Value of i is 3 3 3 3 Value of j is 1000 Value of k is 2000
  • 26.