SlideShare a Scribd company logo
1 of 22
‘ *’  ,  ‘&’     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
int a[10] = {1,2,3,4,5,6,7,8,9,12} ,*p, *q , i; p = &a[2]; q = &a[5]; i = *q - *p;  Printf(“The value of i is %d” i ); i = *p - *q;  Printf(“The value of i is %d” i ); a[2] = a[5] = 0; Printf(“The value of i is %d” i ); Work to your Brain
The value of i is 3 The value of i is -3 The value of i is 0
int a[10] = { 2,3,4,5,6,7,8,9,1,0 }, *p, *q; p = &a[2]; q = p + 3;  p = q – 1;  p+ + ;  Printf(“The value of p and q are : %d , %d” *p,*q); Work to your Brain
The value of p and q are : 7 , 7
int main() { int x[2]={1,2},y[2]={3,4}; int small,big; small=&x[0]; big=&y[0]; min_max(&small,&big); printf(“small%d big%d&quot;,*small,*big); return 0; } min_max(int *a,int *b) { a++; b++; return (*a,*b); } Work to your Brain
Small 2 big 4
 
 

More Related Content

What's hot (20)

detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c language
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.
 
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...
 
C Pointers
C PointersC Pointers
C Pointers
 
Pointers In C
Pointers In CPointers In C
Pointers In C
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
Function in C program
Function in C programFunction in C program
Function in C program
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
Python Data-Types
Python Data-TypesPython Data-Types
Python Data-Types
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
Python Pandas
Python PandasPython Pandas
Python Pandas
 
Array and string
Array and stringArray and string
Array and string
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and Lexeme
 
C Programming : Pointers and Strings
C Programming : Pointers and StringsC Programming : Pointers and Strings
C Programming : Pointers and Strings
 
PHP array 1
PHP array 1PHP array 1
PHP array 1
 

Similar to 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
 
9. pointer, pointer & function
9. pointer, pointer & function9. pointer, pointer & function
9. pointer, pointer & function웅식 전
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...GkhanGirgin3
 
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
 
Ch6 pointers (latest)
Ch6 pointers (latest)Ch6 pointers (latest)
Ch6 pointers (latest)Hattori Sidek
 
10. array & pointer
10. array & pointer10. array & pointer
10. array & pointer웅식 전
 

Similar to Pointers in C (20)

Pointers in c
Pointers in cPointers in c
Pointers in c
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
c programming
c programmingc programming
c programming
 
pointers 1
pointers 1pointers 1
pointers 1
 
Unit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptxUnit-I Pointer Data structure.pptx
Unit-I Pointer Data structure.pptx
 
9. pointer, pointer & function
9. pointer, pointer & function9. pointer, pointer & function
9. pointer, pointer & function
 
Chapter5.pptx
Chapter5.pptxChapter5.pptx
Chapter5.pptx
 
Pointers
PointersPointers
Pointers
 
Pointers in c++ by minal
Pointers in c++ by minalPointers in c++ by minal
Pointers in c++ by minal
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
 
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...
 
Pointers
PointersPointers
Pointers
 
Ch6 pointers (latest)
Ch6 pointers (latest)Ch6 pointers (latest)
Ch6 pointers (latest)
 
CSE240 Pointers
CSE240 PointersCSE240 Pointers
CSE240 Pointers
 
Ch 7-pointers
Ch 7-pointersCh 7-pointers
Ch 7-pointers
 
10. array & pointer
10. array & pointer10. array & pointer
10. array & pointer
 
Pointers+(2)
Pointers+(2)Pointers+(2)
Pointers+(2)
 
Pointer
PointerPointer
Pointer
 
4 Pointers.pptx
4 Pointers.pptx4 Pointers.pptx
4 Pointers.pptx
 
Pointer.pptx
Pointer.pptxPointer.pptx
Pointer.pptx
 

Recently uploaded

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

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. int a[10] = {1,2,3,4,5,6,7,8,9,12} ,*p, *q , i; p = &a[2]; q = &a[5]; i = *q - *p; Printf(“The value of i is %d” i ); i = *p - *q; Printf(“The value of i is %d” i ); a[2] = a[5] = 0; Printf(“The value of i is %d” i ); Work to your Brain
  • 16. The value of i is 3 The value of i is -3 The value of i is 0
  • 17. int a[10] = { 2,3,4,5,6,7,8,9,1,0 }, *p, *q; p = &a[2]; q = p + 3; p = q – 1; p+ + ; Printf(“The value of p and q are : %d , %d” *p,*q); Work to your Brain
  • 18. The value of p and q are : 7 , 7
  • 19. int main() { int x[2]={1,2},y[2]={3,4}; int small,big; small=&x[0]; big=&y[0]; min_max(&small,&big); printf(“small%d big%d&quot;,*small,*big); return 0; } min_max(int *a,int *b) { a++; b++; return (*a,*b); } Work to your Brain
  • 21.  
  • 22.