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 Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptxmary850239
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...DhatriParmar
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
 
Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesVijayaLaxmi84
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
ARTERIAL BLOOD GAS ANALYSIS........pptx
ARTERIAL BLOOD  GAS ANALYSIS........pptxARTERIAL BLOOD  GAS ANALYSIS........pptx
ARTERIAL BLOOD GAS ANALYSIS........pptxAneriPatwari
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfChristalin Nelson
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...DhatriParmar
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 

Recently uploaded (20)

How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
 
Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their uses
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
ARTERIAL BLOOD GAS ANALYSIS........pptx
ARTERIAL BLOOD  GAS ANALYSIS........pptxARTERIAL BLOOD  GAS ANALYSIS........pptx
ARTERIAL BLOOD GAS ANALYSIS........pptx
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdf
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 

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?