SlideShare a Scribd company logo
1 of 17
Lecture 13Lecture 13
Version 1.0Version 1.0
Introduction to PointersIntroduction to Pointers
2Rushdi Shams, Dept of CSE, KUET, Bangladesh
PreludePrelude
 The most crucial of all of C’s grammars isThe most crucial of all of C’s grammars is
pointerspointers
 Many other programming languages have theMany other programming languages have the
similar concept as pointer in Csimilar concept as pointer in C
 they merely do not use the best of pointersthey merely do not use the best of pointers
 C uses pointers as its inevitable partC uses pointers as its inevitable part
 once you have the clean idea on pointers, youonce you have the clean idea on pointers, you
will see that by using pointers, you can solve anywill see that by using pointers, you can solve any
problem in Cproblem in C
3Rushdi Shams, Dept of CSE, KUET, Bangladesh
Concept of Variable, Value &Concept of Variable, Value &
AddressAddress
int i = 3;int i = 3;
 This declaration tells the C compiler to:This declaration tells the C compiler to:
(a) Reserve space in memory to hold the integer(a) Reserve space in memory to hold the integer
value.value.
(b) Associate the name(b) Associate the name ii with this memorywith this memory
location.location.
(c) Store the value 3 at this location.(c) Store the value 3 at this location.
4Rushdi Shams, Dept of CSE, KUET, Bangladesh
Concept of Variable, Value &Concept of Variable, Value &
AddressAddress
 The important point is,The important point is, ii’s address in memory is a’s address in memory is a
number.number.
5Rushdi Shams, Dept of CSE, KUET, Bangladesh
Concept of Variable, Value &Concept of Variable, Value &
AddressAddress
6Rushdi Shams, Dept of CSE, KUET, Bangladesh
Concept of Variable, Value &Concept of Variable, Value &
AddressAddress
 The other pointer operator available in C is ‘The other pointer operator available in C is ‘*’*’
 called ‘value at address’ operatorcalled ‘value at address’ operator
 It gives the value stored at a particular addressIt gives the value stored at a particular address
 The ‘value at address’ operator is also calledThe ‘value at address’ operator is also called
‘indirection’ operator‘indirection’ operator
7Rushdi Shams, Dept of CSE, KUET, Bangladesh
Concept of Variable, Value &Concept of Variable, Value &
AddressAddress
8Rushdi Shams, Dept of CSE, KUET, Bangladesh
Concept of PointerConcept of Pointer
 The expressionThe expression &i&i gives the address of thegives the address of the
variablevariable ii
 This address can be collected in a variableThis address can be collected in a variable
j = &i ;j = &i ;
 But remember thatBut remember that jj is not an ordinary variableis not an ordinary variable
like any other integer variablelike any other integer variable
 It is a variable that contains the address of otherIt is a variable that contains the address of other
variablevariable
9Rushdi Shams, Dept of CSE, KUET, Bangladesh
Concept of PointerConcept of Pointer
 As you can see,As you can see, ii’s value is 3 and’s value is 3 and jj’s value is’s value is ii’s address’s address
10Rushdi Shams, Dept of CSE, KUET, Bangladesh
Concept of PointerConcept of Pointer
 But wait, we can’t useBut wait, we can’t use jj in a program withoutin a program without
declaring itdeclaring it
 sincesince jj is a variable that contains the address ofis a variable that contains the address of ii, it is, it is
declared as,declared as,
int *j ;int *j ;
 This declaration tells the compiler thatThis declaration tells the compiler that jj will be usedwill be used
to store the address of an integer valueto store the address of an integer value
 In other wordsIn other words jj points to an integerpoints to an integer
11Rushdi Shams, Dept of CSE, KUET, Bangladesh
Concept of PointerConcept of Pointer
 int *jint *j would mean, the value at the address containedwould mean, the value at the address contained
inin jj is anis an intint
12Rushdi Shams, Dept of CSE, KUET, Bangladesh
Concept of PointerConcept of Pointer
13Rushdi Shams, Dept of CSE, KUET, Bangladesh
Concept of PointerConcept of Pointer
 Look at the following declarations,Look at the following declarations,
1.1. int *alpha ;int *alpha ;
2.2. char *ch ;char *ch ;
3.3. float *s ;float *s ;
 The declarationThe declaration float *sfloat *s does not mean thatdoes not mean that ss
is going to contain a floating-point valueis going to contain a floating-point value
 ss is going to contain the address of a floating-is going to contain the address of a floating-
point valuepoint value
14Rushdi Shams, Dept of CSE, KUET, Bangladesh
Concept of PointerConcept of Pointer
 Pointer, we know is a variable that containsPointer, we know is a variable that contains
address of another variableaddress of another variable
 Now this variable itself might be another pointerNow this variable itself might be another pointer
 Thus, we now have a pointer that containsThus, we now have a pointer that contains
another pointer’s addressanother pointer’s address
15Rushdi Shams, Dept of CSE, KUET, Bangladesh
Concept of PointerConcept of Pointer
16Rushdi Shams, Dept of CSE, KUET, Bangladesh
Concept of PointerConcept of Pointer
 i is an ordinaryi is an ordinary intint
 jj is a pointer to anis a pointer to an intint
 kk is a pointer to an integer pointeris a pointer to an integer pointer
17Rushdi Shams, Dept of CSE, KUET, Bangladesh
Concept of PointerConcept of Pointer
 what will be the output?what will be the output?

More Related Content

What's hot

General Talk on Pointers
General Talk on PointersGeneral Talk on Pointers
General Talk on Pointersguest9c2f4c
 
Neural machine translation of rare words with subword units
Neural machine translation of rare words with subword unitsNeural machine translation of rare words with subword units
Neural machine translation of rare words with subword unitsTae Hwan Jung
 
Statistical machine translation
Statistical machine translationStatistical machine translation
Statistical machine translationHrishikesh Nair
 
Coding and decoding topic for aptitude
Coding and decoding topic for aptitudeCoding and decoding topic for aptitude
Coding and decoding topic for aptitudeavdheshtripathi2
 
HMM BASED POS TAGGER FOR HINDI
HMM BASED POS TAGGER FOR HINDIHMM BASED POS TAGGER FOR HINDI
HMM BASED POS TAGGER FOR HINDIcscpconf
 

What's hot (10)

General Talk on Pointers
General Talk on PointersGeneral Talk on Pointers
General Talk on Pointers
 
C basics by haseeb khan
C basics by haseeb khanC basics by haseeb khan
C basics by haseeb khan
 
NLP and Deep Learning
NLP and Deep LearningNLP and Deep Learning
NLP and Deep Learning
 
Neural machine translation of rare words with subword units
Neural machine translation of rare words with subword unitsNeural machine translation of rare words with subword units
Neural machine translation of rare words with subword units
 
Statistical machine translation
Statistical machine translationStatistical machine translation
Statistical machine translation
 
8 issues in pos tagging
8 issues in pos tagging8 issues in pos tagging
8 issues in pos tagging
 
P-6
P-6P-6
P-6
 
Coding and decoding topic for aptitude
Coding and decoding topic for aptitudeCoding and decoding topic for aptitude
Coding and decoding topic for aptitude
 
Slides bracis 2019
Slides bracis 2019Slides bracis 2019
Slides bracis 2019
 
HMM BASED POS TAGGER FOR HINDI
HMM BASED POS TAGGER FOR HINDIHMM BASED POS TAGGER FOR HINDI
HMM BASED POS TAGGER FOR HINDI
 

Viewers also liked

Lec 04. If-Else Statement / Increment and Decrement Operators
Lec 04. If-Else Statement / Increment and Decrement OperatorsLec 04. If-Else Statement / Increment and Decrement Operators
Lec 04. If-Else Statement / Increment and Decrement OperatorsRushdi Shams
 

Viewers also liked (7)

Lec 04. If-Else Statement / Increment and Decrement Operators
Lec 04. If-Else Statement / Increment and Decrement OperatorsLec 04. If-Else Statement / Increment and Decrement Operators
Lec 04. If-Else Statement / Increment and Decrement Operators
 
Structure
StructureStructure
Structure
 
Recursion prog
Recursion progRecursion prog
Recursion prog
 
Recursion prog (1)
Recursion prog (1)Recursion prog (1)
Recursion prog (1)
 
Lec 18. Recursion
Lec 18. RecursionLec 18. Recursion
Lec 18. Recursion
 
Pointers
PointersPointers
Pointers
 
Type conversion
Type conversionType conversion
Type conversion
 

Similar to Lec 13. Introduction to Pointers

Lec 10. Functions (Part II)
Lec 10. Functions (Part II)Lec 10. Functions (Part II)
Lec 10. Functions (Part II)Rushdi Shams
 
Programming in Computer Science- Pointers in C++.ppt
Programming in Computer Science- Pointers in C++.pptProgramming in Computer Science- Pointers in C++.ppt
Programming in Computer Science- Pointers in C++.pptrichardbaahnkansah
 
chapter-11-pointers.pdf
chapter-11-pointers.pdfchapter-11-pointers.pdf
chapter-11-pointers.pdfstudy material
 
Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++Gamindu Udayanga
 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programmingnmahi96
 
UNIT III POINTERS IN C
UNIT III POINTERS IN C UNIT III POINTERS IN C
UNIT III POINTERS IN C Sanjay Kale
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
Lec 03. Arithmetic Operator / Relational Operator
Lec 03. Arithmetic Operator / Relational OperatorLec 03. Arithmetic Operator / Relational Operator
Lec 03. Arithmetic Operator / Relational OperatorRushdi Shams
 
C Prog. - Data Types, Variables and Constants
C Prog. - Data Types, Variables and ConstantsC Prog. - Data Types, Variables and Constants
C Prog. - Data Types, Variables and Constantsvinay arora
 
Chapter1 c programming data types, variables and constants
Chapter1 c programming   data types, variables and constantsChapter1 c programming   data types, variables and constants
Chapter1 c programming data types, variables and constantsvinay arora
 
Pointers in c
Pointers in cPointers in c
Pointers in cMohd Arif
 
Lec 14. Call by Reference
Lec 14. Call by ReferenceLec 14. Call by Reference
Lec 14. Call by ReferenceRushdi Shams
 
Lec 15. Pointers and Arrays
Lec 15. Pointers and ArraysLec 15. Pointers and Arrays
Lec 15. Pointers and ArraysRushdi Shams
 
VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3YOGESH SINGH
 

Similar to Lec 13. Introduction to Pointers (20)

Lec 10. Functions (Part II)
Lec 10. Functions (Part II)Lec 10. Functions (Part II)
Lec 10. Functions (Part II)
 
Programming in Computer Science- Pointers in C++.ppt
Programming in Computer Science- Pointers in C++.pptProgramming in Computer Science- Pointers in C++.ppt
Programming in Computer Science- Pointers in C++.ppt
 
chapter-11-pointers.pdf
chapter-11-pointers.pdfchapter-11-pointers.pdf
chapter-11-pointers.pdf
 
Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programming
 
UNIT III POINTERS IN C
UNIT III POINTERS IN C UNIT III POINTERS IN C
UNIT III POINTERS IN C
 
Pointers in C language
Pointers  in  C languagePointers  in  C language
Pointers in C language
 
Pointers
PointersPointers
Pointers
 
C pointer
C pointerC pointer
C pointer
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
 
Lec 03. Arithmetic Operator / Relational Operator
Lec 03. Arithmetic Operator / Relational OperatorLec 03. Arithmetic Operator / Relational Operator
Lec 03. Arithmetic Operator / Relational Operator
 
C Prog. - Data Types, Variables and Constants
C Prog. - Data Types, Variables and ConstantsC Prog. - Data Types, Variables and Constants
C Prog. - Data Types, Variables and Constants
 
Chapter1 c programming data types, variables and constants
Chapter1 c programming   data types, variables and constantsChapter1 c programming   data types, variables and constants
Chapter1 c programming data types, variables and constants
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.
 
Lec 14. Call by Reference
Lec 14. Call by ReferenceLec 14. Call by Reference
Lec 14. Call by Reference
 
Lec 15. Pointers and Arrays
Lec 15. Pointers and ArraysLec 15. Pointers and Arrays
Lec 15. Pointers and Arrays
 
VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3VIT351 Software Development VI Unit3
VIT351 Software Development VI Unit3
 

More from Rushdi Shams

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 ResearchRushdi Shams
 
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 IRRushdi Shams
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101Rushdi Shams
 
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 processingRushdi Shams
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: ParsingRushdi Shams
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translationRushdi 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 translationRushdi Shams
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semanticsRushdi Shams
 
Propositional logic
Propositional logicPropositional logic
Propositional logicRushdi Shams
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logicRushdi Shams
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structureRushdi Shams
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representationRushdi Shams
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hackingRushdi Shams
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)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
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic 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
 

Recently uploaded

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 17Celine George
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
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).pptxVishalSingh1417
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 

Recently uploaded (20)

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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
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
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 

Lec 13. Introduction to Pointers

  • 1. Lecture 13Lecture 13 Version 1.0Version 1.0 Introduction to PointersIntroduction to Pointers
  • 2. 2Rushdi Shams, Dept of CSE, KUET, Bangladesh PreludePrelude  The most crucial of all of C’s grammars isThe most crucial of all of C’s grammars is pointerspointers  Many other programming languages have theMany other programming languages have the similar concept as pointer in Csimilar concept as pointer in C  they merely do not use the best of pointersthey merely do not use the best of pointers  C uses pointers as its inevitable partC uses pointers as its inevitable part  once you have the clean idea on pointers, youonce you have the clean idea on pointers, you will see that by using pointers, you can solve anywill see that by using pointers, you can solve any problem in Cproblem in C
  • 3. 3Rushdi Shams, Dept of CSE, KUET, Bangladesh Concept of Variable, Value &Concept of Variable, Value & AddressAddress int i = 3;int i = 3;  This declaration tells the C compiler to:This declaration tells the C compiler to: (a) Reserve space in memory to hold the integer(a) Reserve space in memory to hold the integer value.value. (b) Associate the name(b) Associate the name ii with this memorywith this memory location.location. (c) Store the value 3 at this location.(c) Store the value 3 at this location.
  • 4. 4Rushdi Shams, Dept of CSE, KUET, Bangladesh Concept of Variable, Value &Concept of Variable, Value & AddressAddress  The important point is,The important point is, ii’s address in memory is a’s address in memory is a number.number.
  • 5. 5Rushdi Shams, Dept of CSE, KUET, Bangladesh Concept of Variable, Value &Concept of Variable, Value & AddressAddress
  • 6. 6Rushdi Shams, Dept of CSE, KUET, Bangladesh Concept of Variable, Value &Concept of Variable, Value & AddressAddress  The other pointer operator available in C is ‘The other pointer operator available in C is ‘*’*’  called ‘value at address’ operatorcalled ‘value at address’ operator  It gives the value stored at a particular addressIt gives the value stored at a particular address  The ‘value at address’ operator is also calledThe ‘value at address’ operator is also called ‘indirection’ operator‘indirection’ operator
  • 7. 7Rushdi Shams, Dept of CSE, KUET, Bangladesh Concept of Variable, Value &Concept of Variable, Value & AddressAddress
  • 8. 8Rushdi Shams, Dept of CSE, KUET, Bangladesh Concept of PointerConcept of Pointer  The expressionThe expression &i&i gives the address of thegives the address of the variablevariable ii  This address can be collected in a variableThis address can be collected in a variable j = &i ;j = &i ;  But remember thatBut remember that jj is not an ordinary variableis not an ordinary variable like any other integer variablelike any other integer variable  It is a variable that contains the address of otherIt is a variable that contains the address of other variablevariable
  • 9. 9Rushdi Shams, Dept of CSE, KUET, Bangladesh Concept of PointerConcept of Pointer  As you can see,As you can see, ii’s value is 3 and’s value is 3 and jj’s value is’s value is ii’s address’s address
  • 10. 10Rushdi Shams, Dept of CSE, KUET, Bangladesh Concept of PointerConcept of Pointer  But wait, we can’t useBut wait, we can’t use jj in a program withoutin a program without declaring itdeclaring it  sincesince jj is a variable that contains the address ofis a variable that contains the address of ii, it is, it is declared as,declared as, int *j ;int *j ;  This declaration tells the compiler thatThis declaration tells the compiler that jj will be usedwill be used to store the address of an integer valueto store the address of an integer value  In other wordsIn other words jj points to an integerpoints to an integer
  • 11. 11Rushdi Shams, Dept of CSE, KUET, Bangladesh Concept of PointerConcept of Pointer  int *jint *j would mean, the value at the address containedwould mean, the value at the address contained inin jj is anis an intint
  • 12. 12Rushdi Shams, Dept of CSE, KUET, Bangladesh Concept of PointerConcept of Pointer
  • 13. 13Rushdi Shams, Dept of CSE, KUET, Bangladesh Concept of PointerConcept of Pointer  Look at the following declarations,Look at the following declarations, 1.1. int *alpha ;int *alpha ; 2.2. char *ch ;char *ch ; 3.3. float *s ;float *s ;  The declarationThe declaration float *sfloat *s does not mean thatdoes not mean that ss is going to contain a floating-point valueis going to contain a floating-point value  ss is going to contain the address of a floating-is going to contain the address of a floating- point valuepoint value
  • 14. 14Rushdi Shams, Dept of CSE, KUET, Bangladesh Concept of PointerConcept of Pointer  Pointer, we know is a variable that containsPointer, we know is a variable that contains address of another variableaddress of another variable  Now this variable itself might be another pointerNow this variable itself might be another pointer  Thus, we now have a pointer that containsThus, we now have a pointer that contains another pointer’s addressanother pointer’s address
  • 15. 15Rushdi Shams, Dept of CSE, KUET, Bangladesh Concept of PointerConcept of Pointer
  • 16. 16Rushdi Shams, Dept of CSE, KUET, Bangladesh Concept of PointerConcept of Pointer  i is an ordinaryi is an ordinary intint  jj is a pointer to anis a pointer to an intint  kk is a pointer to an integer pointeris a pointer to an integer pointer
  • 17. 17Rushdi Shams, Dept of CSE, KUET, Bangladesh Concept of PointerConcept of Pointer  what will be the output?what will be the output?