SlideShare uma empresa Scribd logo
1 de 16
‘ *’  ,  ‘&’     Pointers In C
About me Sriram kumar . K III rd year CSE  Email - Sri2k42002@yahoo.co.in
What is a Pointer ?
X1000 X1004 X1008 X100c x1010 Who does a memory look like ? X1000 X1001 X1002 X1003   Address Locations
Operators used in Pointers  * & Address Dereferencing (Address of) (Value of)
Int i=3; Address of ‘i’ Value of ‘i’ X1000  x1004  x1008  x100c  x1010  x1014 variable i 3 (Value of i) Address of i ‘ &i’ ‘ *i’ The value ‘3’ is saved in the memory location ‘x100c’
Syntax for pointers (pointer type declaration) type *identifier ; Example  Char *cp ; Int *ip ; Double *dp ;
Pointer Assignment   Int i = 1 , *ip ;  //pointer declaration   ip = &i ;  //pointer assignment *ip = 3 ;  //pointer assignment
Pointer Arithmetic Lets take this example program #include<stdio.h> Void main() { Int a [5]={1,2,3,4,5} , b , *pt ; pt = &a[0]; pt = pt + 4 ; b=a[0] ;  b+=4 ; } a[0] X1000  x1004  x1008  x100c  x1010 X1000  x1004  x1008  x100c  x1010 a[2] a[1] a[4] a[3] a[0] a[2] a[1] a[4] a[3] b b = 1  b=1+4  b= 5 pt
Lets Take an Example and See how pointers work #include<stdio.h> Void main() { Int i=3; Int *j; j=&i; Printf(“i=%d”i); Printf(“*j=%d”*j); }
X1000  x1004  x1008  x100c  x1010  x1014 3 Memory variables Int i Int *j Int i=3; Int *j; j = &i; x100c Create an integer variable ‘i’ and initialize it to 3 Create a pointer variable ‘j’- create  value of ‘j’ Initialize the pointer  value of ‘j’  to the  address of ‘i’
X1000  x1004  x1008  x100c  x1010  x1014 Memory variables Int i Int *j Output screen Printf(“i=%d” i); We know j=&i So    *j=*(&i) value of (address of i) (i.e.) value in address (x100c) Printf(“i=%d” i); i=3 *j=3 Printf(“*j=%d” *j); Printf(“*j=%d” *j); x100c 3 3
Void main() { int num=10; int* pnum=NULL; pnum = &num; *pnum += 20; printf(&quot;Number = %d&quot;, num); printf(&quot;Pointer Number = %d&quot;, *pnum); } Predict the output of this code
Number = 10 Pointer Number = 30
 
 

Mais conteúdo relacionado

Mais procurados

#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And References#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And ReferencesHadziq Fabroyir
 
9. pointer, pointer & function
9. pointer, pointer & function9. pointer, pointer & function
9. pointer, pointer & function웅식 전
 
C programming structure & pointer
C  programming structure & pointerC  programming structure & pointer
C programming structure & pointerargusacademy
 
#OOP_D_ITS - 2nd - C++ Getting Started
#OOP_D_ITS - 2nd - C++ Getting Started#OOP_D_ITS - 2nd - C++ Getting Started
#OOP_D_ITS - 2nd - C++ Getting StartedHadziq Fabroyir
 
C tech questions
C tech questionsC tech questions
C tech questionsvijay00791
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2vikram mahendra
 
Data structure week 2
Data structure week 2Data structure week 2
Data structure week 2karmuhtam
 
Function recap
Function recapFunction recap
Function recapalish sha
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2Amit Kapoor
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...ssuserd6b1fd
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocationMohammad Usman
 
Lab 10 sem ii_12_13
Lab 10 sem ii_12_13Lab 10 sem ii_12_13
Lab 10 sem ii_12_13alish sha
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONvikram mahendra
 

Mais procurados (20)

Pointer in C
Pointer in CPointer in C
Pointer in C
 
#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And References#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And References
 
CSE240 Pointers
CSE240 PointersCSE240 Pointers
CSE240 Pointers
 
Pointers
PointersPointers
Pointers
 
9. pointer, pointer & function
9. pointer, pointer & function9. pointer, pointer & function
9. pointer, pointer & function
 
Pointers_c
Pointers_cPointers_c
Pointers_c
 
Lecture 17 - Strings
Lecture 17 - StringsLecture 17 - Strings
Lecture 17 - Strings
 
Pointers+(2)
Pointers+(2)Pointers+(2)
Pointers+(2)
 
C programming structure & pointer
C  programming structure & pointerC  programming structure & pointer
C programming structure & pointer
 
#OOP_D_ITS - 2nd - C++ Getting Started
#OOP_D_ITS - 2nd - C++ Getting Started#OOP_D_ITS - 2nd - C++ Getting Started
#OOP_D_ITS - 2nd - C++ Getting Started
 
C tech questions
C tech questionsC tech questions
C tech questions
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
 
Data structure week 2
Data structure week 2Data structure week 2
Data structure week 2
 
Function recap
Function recapFunction recap
Function recap
 
Lecture 18 - Pointers
Lecture 18 - PointersLecture 18 - Pointers
Lecture 18 - Pointers
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
Lab 10 sem ii_12_13
Lab 10 sem ii_12_13Lab 10 sem ii_12_13
Lab 10 sem ii_12_13
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
 

Destaque

εκε Green Evolution 2
εκε Green Evolution 2εκε Green Evolution 2
εκε Green Evolution 2OESYNE
 
Bluevibe@Fsc1
Bluevibe@Fsc1Bluevibe@Fsc1
Bluevibe@Fsc1OESYNE
 
Money Show 2009
Money Show 2009Money Show 2009
Money Show 2009OESYNE
 
Ed Present Nov 09 Esyne
Ed Present Nov 09 EsyneEd Present Nov 09 Esyne
Ed Present Nov 09 EsyneOESYNE
 
Знакомство с Papervision3d
Знакомство с Papervision3dЗнакомство с Papervision3d
Знакомство с Papervision3dIgor Ruzanov
 
Green Evolution Profile 1
Green Evolution   Profile   1Green Evolution   Profile   1
Green Evolution Profile 1OESYNE
 
Dimitris_Tsigos_ISTAME_20110228
Dimitris_Tsigos_ISTAME_20110228Dimitris_Tsigos_ISTAME_20110228
Dimitris_Tsigos_ISTAME_20110228OESYNE
 

Destaque (9)

εκε Green Evolution 2
εκε Green Evolution 2εκε Green Evolution 2
εκε Green Evolution 2
 
Bluevibe@Fsc1
Bluevibe@Fsc1Bluevibe@Fsc1
Bluevibe@Fsc1
 
Money Show 2009
Money Show 2009Money Show 2009
Money Show 2009
 
Ed Present Nov 09 Esyne
Ed Present Nov 09 EsyneEd Present Nov 09 Esyne
Ed Present Nov 09 Esyne
 
Main Menu
Main MenuMain Menu
Main Menu
 
Знакомство с Papervision3d
Знакомство с Papervision3dЗнакомство с Papervision3d
Знакомство с Papervision3d
 
Green Evolution Profile 1
Green Evolution   Profile   1Green Evolution   Profile   1
Green Evolution Profile 1
 
Cobit
CobitCobit
Cobit
 
Dimitris_Tsigos_ISTAME_20110228
Dimitris_Tsigos_ISTAME_20110228Dimitris_Tsigos_ISTAME_20110228
Dimitris_Tsigos_ISTAME_20110228
 

Semelhante a Pointers in c

Unit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptxUnit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptxajajkhan16
 
Ch6 pointers (latest)
Ch6 pointers (latest)Ch6 pointers (latest)
Ch6 pointers (latest)Hattori Sidek
 
Chapter 5 (Part I) - Pointers.pdf
Chapter 5 (Part I) - Pointers.pdfChapter 5 (Part I) - Pointers.pdf
Chapter 5 (Part I) - Pointers.pdfTamiratDejene1
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...GkhanGirgin3
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Jayanshu Gundaniya
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanMohammadSalman129
 
Engineering Computers L32-L33-Pointers.pptx
Engineering Computers L32-L33-Pointers.pptxEngineering Computers L32-L33-Pointers.pptx
Engineering Computers L32-L33-Pointers.pptxhappycocoman
 

Semelhante a Pointers in c (20)

Pointers
PointersPointers
Pointers
 
c programming
c programmingc programming
c programming
 
Unit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptxUnit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptx
 
Pointers in c++ by minal
Pointers in c++ by minalPointers in c++ by minal
Pointers in c++ by minal
 
Pointer.pptx
Pointer.pptxPointer.pptx
Pointer.pptx
 
Ch6 pointers (latest)
Ch6 pointers (latest)Ch6 pointers (latest)
Ch6 pointers (latest)
 
C pointers
C pointersC pointers
C pointers
 
Ch 7-pointers
Ch 7-pointersCh 7-pointers
Ch 7-pointers
 
Chapter 5 (Part I) - Pointers.pdf
Chapter 5 (Part I) - Pointers.pdfChapter 5 (Part I) - Pointers.pdf
Chapter 5 (Part I) - Pointers.pdf
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
 
Pointers
PointersPointers
Pointers
 
pointers 1
pointers 1pointers 1
pointers 1
 
POINTERS IN C
POINTERS IN CPOINTERS IN C
POINTERS IN C
 
Pointers
PointersPointers
Pointers
 
C Programming Unit-4
C Programming Unit-4C Programming Unit-4
C Programming Unit-4
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
 
Unit 6 pointers
Unit 6   pointersUnit 6   pointers
Unit 6 pointers
 
Pointer
PointerPointer
Pointer
 
Engineering Computers L32-L33-Pointers.pptx
Engineering Computers L32-L33-Pointers.pptxEngineering Computers L32-L33-Pointers.pptx
Engineering Computers L32-L33-Pointers.pptx
 

Último

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 

Último (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 

Pointers in c

  • 1. ‘ *’ , ‘&’  Pointers In C
  • 2. About me Sriram kumar . K III rd year CSE Email - Sri2k42002@yahoo.co.in
  • 3. What is a Pointer ?
  • 4. X1000 X1004 X1008 X100c x1010 Who does a memory look like ? X1000 X1001 X1002 X1003 Address Locations
  • 5. Operators used in Pointers * & Address Dereferencing (Address of) (Value of)
  • 6. Int i=3; Address of ‘i’ Value of ‘i’ X1000 x1004 x1008 x100c x1010 x1014 variable i 3 (Value of i) Address of i ‘ &i’ ‘ *i’ The value ‘3’ is saved in the memory location ‘x100c’
  • 7. Syntax for pointers (pointer type declaration) type *identifier ; Example Char *cp ; Int *ip ; Double *dp ;
  • 8. Pointer Assignment Int i = 1 , *ip ; //pointer declaration ip = &i ; //pointer assignment *ip = 3 ; //pointer assignment
  • 9. Pointer Arithmetic Lets take this example program #include<stdio.h> Void main() { Int a [5]={1,2,3,4,5} , b , *pt ; pt = &a[0]; pt = pt + 4 ; b=a[0] ; b+=4 ; } a[0] X1000 x1004 x1008 x100c x1010 X1000 x1004 x1008 x100c x1010 a[2] a[1] a[4] a[3] a[0] a[2] a[1] a[4] a[3] b b = 1 b=1+4 b= 5 pt
  • 10. Lets Take an Example and See how pointers work #include<stdio.h> Void main() { Int i=3; Int *j; j=&i; Printf(“i=%d”i); Printf(“*j=%d”*j); }
  • 11. X1000 x1004 x1008 x100c x1010 x1014 3 Memory variables Int i Int *j Int i=3; Int *j; j = &i; x100c Create an integer variable ‘i’ and initialize it to 3 Create a pointer variable ‘j’- create value of ‘j’ Initialize the pointer value of ‘j’ to the address of ‘i’
  • 12. X1000 x1004 x1008 x100c x1010 x1014 Memory variables Int i Int *j Output screen Printf(“i=%d” i); We know j=&i So  *j=*(&i) value of (address of i) (i.e.) value in address (x100c) Printf(“i=%d” i); i=3 *j=3 Printf(“*j=%d” *j); Printf(“*j=%d” *j); x100c 3 3
  • 13. Void main() { int num=10; int* pnum=NULL; pnum = &num; *pnum += 20; printf(&quot;Number = %d&quot;, num); printf(&quot;Pointer Number = %d&quot;, *pnum); } Predict the output of this code
  • 14. Number = 10 Pointer Number = 30
  • 15.  
  • 16.