SlideShare a Scribd company logo
1 of 18
Lecture 15Lecture 15
Version 1.0Version 1.0
Pointers and ArraysPointers and Arrays
2Rushdi Shams, Dept of CSE, KUET, Bangladesh
Passing Array Elements to FunctionsPassing Array Elements to Functions
 Array elements can be passed to a function byArray elements can be passed to a function by
calling the function by value, or by referencecalling the function by value, or by reference
 In the call by value we pass values of arrayIn the call by value we pass values of array
elements to the functionelements to the function
 in the call by reference we pass addresses ofin the call by reference we pass addresses of
array elements to the functionarray elements to the function
3Rushdi Shams, Dept of CSE, KUET, Bangladesh
Passing Array Elements toPassing Array Elements to
Functions: Call by valueFunctions: Call by value
4Rushdi Shams, Dept of CSE, KUET, Bangladesh
Passing Array Elements toPassing Array Elements to
Functions: Call by referenceFunctions: Call by reference
5Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointer ArithmeticPointer Arithmetic
6Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointer ArithmeticPointer Arithmetic
 Addition of a number to a pointerAddition of a number to a pointer
7Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointer ArithmeticPointer Arithmetic
 Subtraction of a number from a pointerSubtraction of a number from a pointer
8Rushdi Shams, Dept of CSE, KUET, Bangladesh
What do we know so far?What do we know so far?
 Array elements are always stored in contiguousArray elements are always stored in contiguous
memory locations.memory locations.
 A pointer when incremented always points to anA pointer when incremented always points to an
immediately next location of its type.immediately next location of its type.
9Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointers and ArraysPointers and Arrays
10Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointer and ArrayPointer and Array
 Our next two programs show ways in which weOur next two programs show ways in which we
can access the elements of this array.can access the elements of this array.
11Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointer and ArrayPointer and Array
12Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointer and ArrayPointer and Array
13Rushdi Shams, Dept of CSE, KUET, Bangladesh
Passing entire array to functionPassing entire array to function
14Rushdi Shams, Dept of CSE, KUET, Bangladesh
Similar Statements!Similar Statements!
15Rushdi Shams, Dept of CSE, KUET, Bangladesh
Array of PointersArray of Pointers
 The way there can be an array ofThe way there can be an array of intints or an arrays or an array
ofof floatfloats, similarly there can be an array ofs, similarly there can be an array of
pointerspointers
 an array of pointers would be nothing but aan array of pointers would be nothing but a
collection of addressescollection of addresses
16Rushdi Shams, Dept of CSE, KUET, Bangladesh
Array of pointersArray of pointers
17Rushdi Shams, Dept of CSE, KUET, Bangladesh
Array of pointersArray of pointers
18Rushdi Shams, Dept of CSE, KUET, Bangladesh
Pointers to arrayPointers to array
 An array of pointers can even contain the addressesAn array of pointers can even contain the addresses
of other arraysof other arrays

More Related Content

Similar to Lec 15. Pointers and Arrays

Lec 11. One Dimensional Arrays
Lec 11. One Dimensional ArraysLec 11. One Dimensional Arrays
Lec 11. One Dimensional Arrays
Rushdi Shams
 
Lec 14. Call by Reference
Lec 14. Call by ReferenceLec 14. Call by Reference
Lec 14. Call by Reference
Rushdi Shams
 
L14 l15 Object Oriented DBMS
L14 l15  Object Oriented DBMSL14 l15  Object Oriented DBMS
L14 l15 Object Oriented DBMS
Rushdi Shams
 
Lec 03. Arithmetic Operator / Relational Operator
Lec 03. Arithmetic Operator / Relational OperatorLec 03. Arithmetic Operator / Relational Operator
Lec 03. Arithmetic Operator / Relational Operator
Rushdi Shams
 
My slide relational algebra
My slide  relational algebraMy slide  relational algebra
My slide relational algebra
Rushdi Shams
 
Lec 08. C Data Types
Lec 08. C Data TypesLec 08. C Data Types
Lec 08. C Data Types
Rushdi Shams
 
Lec 07. Do-While Loop / Switch
Lec 07. Do-While Loop / SwitchLec 07. Do-While Loop / Switch
Lec 07. Do-While Loop / Switch
Rushdi Shams
 
L5 aggregate functions
L5  aggregate functionsL5  aggregate functions
L5 aggregate functions
Rushdi Shams
 

Similar to Lec 15. Pointers and Arrays (15)

Lec 11. One Dimensional Arrays
Lec 11. One Dimensional ArraysLec 11. One Dimensional Arrays
Lec 11. One Dimensional Arrays
 
Lec 14. Call by Reference
Lec 14. Call by ReferenceLec 14. Call by Reference
Lec 14. Call by Reference
 
Programming Basics - array, loops, funcitons
Programming Basics - array, loops, funcitonsProgramming Basics - array, loops, funcitons
Programming Basics - array, loops, funcitons
 
L14 l15 Object Oriented DBMS
L14 l15  Object Oriented DBMSL14 l15  Object Oriented DBMS
L14 l15 Object Oriented DBMS
 
Get started with R lang
Get started with R langGet started with R lang
Get started with R lang
 
Lec 03. Arithmetic Operator / Relational Operator
Lec 03. Arithmetic Operator / Relational OperatorLec 03. Arithmetic Operator / Relational Operator
Lec 03. Arithmetic Operator / Relational Operator
 
Lec 16. Strings
Lec 16. StringsLec 16. Strings
Lec 16. Strings
 
QER : query entity recognition
QER : query entity recognitionQER : query entity recognition
QER : query entity recognition
 
My slide relational algebra
My slide  relational algebraMy slide  relational algebra
My slide relational algebra
 
Cg4201552556
Cg4201552556Cg4201552556
Cg4201552556
 
Lec 08. C Data Types
Lec 08. C Data TypesLec 08. C Data Types
Lec 08. C Data Types
 
Training excel
Training  excelTraining  excel
Training excel
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 
Lec 07. Do-While Loop / Switch
Lec 07. Do-While Loop / SwitchLec 07. Do-While Loop / Switch
Lec 07. Do-While Loop / Switch
 
L5 aggregate functions
L5  aggregate functionsL5  aggregate functions
L5 aggregate functions
 

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
 
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
 
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)
 
L1 phishing
L1  phishingL1  phishing
L1 phishing
 
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

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

Lec 15. Pointers and Arrays

  • 1. Lecture 15Lecture 15 Version 1.0Version 1.0 Pointers and ArraysPointers and Arrays
  • 2. 2Rushdi Shams, Dept of CSE, KUET, Bangladesh Passing Array Elements to FunctionsPassing Array Elements to Functions  Array elements can be passed to a function byArray elements can be passed to a function by calling the function by value, or by referencecalling the function by value, or by reference  In the call by value we pass values of arrayIn the call by value we pass values of array elements to the functionelements to the function  in the call by reference we pass addresses ofin the call by reference we pass addresses of array elements to the functionarray elements to the function
  • 3. 3Rushdi Shams, Dept of CSE, KUET, Bangladesh Passing Array Elements toPassing Array Elements to Functions: Call by valueFunctions: Call by value
  • 4. 4Rushdi Shams, Dept of CSE, KUET, Bangladesh Passing Array Elements toPassing Array Elements to Functions: Call by referenceFunctions: Call by reference
  • 5. 5Rushdi Shams, Dept of CSE, KUET, Bangladesh Pointer ArithmeticPointer Arithmetic
  • 6. 6Rushdi Shams, Dept of CSE, KUET, Bangladesh Pointer ArithmeticPointer Arithmetic  Addition of a number to a pointerAddition of a number to a pointer
  • 7. 7Rushdi Shams, Dept of CSE, KUET, Bangladesh Pointer ArithmeticPointer Arithmetic  Subtraction of a number from a pointerSubtraction of a number from a pointer
  • 8. 8Rushdi Shams, Dept of CSE, KUET, Bangladesh What do we know so far?What do we know so far?  Array elements are always stored in contiguousArray elements are always stored in contiguous memory locations.memory locations.  A pointer when incremented always points to anA pointer when incremented always points to an immediately next location of its type.immediately next location of its type.
  • 9. 9Rushdi Shams, Dept of CSE, KUET, Bangladesh Pointers and ArraysPointers and Arrays
  • 10. 10Rushdi Shams, Dept of CSE, KUET, Bangladesh Pointer and ArrayPointer and Array  Our next two programs show ways in which weOur next two programs show ways in which we can access the elements of this array.can access the elements of this array.
  • 11. 11Rushdi Shams, Dept of CSE, KUET, Bangladesh Pointer and ArrayPointer and Array
  • 12. 12Rushdi Shams, Dept of CSE, KUET, Bangladesh Pointer and ArrayPointer and Array
  • 13. 13Rushdi Shams, Dept of CSE, KUET, Bangladesh Passing entire array to functionPassing entire array to function
  • 14. 14Rushdi Shams, Dept of CSE, KUET, Bangladesh Similar Statements!Similar Statements!
  • 15. 15Rushdi Shams, Dept of CSE, KUET, Bangladesh Array of PointersArray of Pointers  The way there can be an array ofThe way there can be an array of intints or an arrays or an array ofof floatfloats, similarly there can be an array ofs, similarly there can be an array of pointerspointers  an array of pointers would be nothing but aan array of pointers would be nothing but a collection of addressescollection of addresses
  • 16. 16Rushdi Shams, Dept of CSE, KUET, Bangladesh Array of pointersArray of pointers
  • 17. 17Rushdi Shams, Dept of CSE, KUET, Bangladesh Array of pointersArray of pointers
  • 18. 18Rushdi Shams, Dept of CSE, KUET, Bangladesh Pointers to arrayPointers to array  An array of pointers can even contain the addressesAn array of pointers can even contain the addresses of other arraysof other arrays