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
 
C basics by haseeb khan
C basics by haseeb khanC basics by haseeb khan
C basics by haseeb khanHaseeb Shalmani
 
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
 
8 issues in pos tagging
8 issues in pos tagging8 issues in pos tagging
8 issues in pos taggingThennarasuSakkan
 
P-6
P-6P-6
P-6butest
 
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
 
Recursion prog
Recursion progRecursion prog
Recursion progFrijo Francis
 
Recursion prog (1)
Recursion prog (1)Recursion prog (1)
Recursion prog (1)Frijo Francis
 
Lec 18. Recursion
Lec 18. RecursionLec 18. Recursion
Lec 18. RecursionRushdi Shams
 
Type conversion
Type conversionType conversion
Type conversionFrijo Francis
 

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
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.Md. Afif Al Mamun
 
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
 
L15 fuzzy logic
L15  fuzzy logicL15  fuzzy logic
L15 fuzzy logicRushdi Shams
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structureRushdi Shams
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representationRushdi Shams
 
First order logic
First order logicFirst order logic
First order logicRushdi Shams
 
Belief function
Belief functionBelief function
Belief functionRushdi 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

MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)Dr. Mazin Mohamed alkathiri
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 

Recently uploaded (20)

MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
 

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?