SlideShare a Scribd company logo
1 of 21
Author – Subhasis Nayak
   Pointer assignments
   Pointer arithmetic
   Pointer comparisons
   Pointers & arrays
   Arrays of pointers
   Multiple indirection
   Pointers to function
   Dynamic allocations
   We know how to point a variable .
      In this example I will show how to point a
       variable from two pointers.

You must pass the vaddres1
to vAddress2.Because we
passed the address of
variable to vaddress1 not to
vAddress2
   There are only two arithmetic operations that
    you may use on pointers:
    ◦ Addition
    ◦ Subtraction
   But you can do all operation on pointer’s
    value as:
    ◦   Addition
    ◦   Subtraction
    ◦   Multiplication
    ◦   division
   There are two type of comparison of pointers
    ◦ In between pointer = this is the comparison held
      between the addresses they hold

                      If (p1>p2)


    ◦ In between pointer value = here we comparing
      between the values they hold.

                     If (*p1>*p2)
   you can direct a pointer to hold the array's address as
    we do for a normal variable.
   As I told you array is a sequence of similar type of
    data type.
   To hold the array's address when you direct the
    pointer to hold array's address it holds the first’s of
    that array address only.
   To get the address of each element of array we have
    to add the exact index number of that element. how
    can we do that? we can do that with help of a loop or
    directly adding the index’s number.
Int array[5];     Int array[5];
Int *Parray;      Int *Parray;
Parray = array;   Parray = &array[0];
   We already learned array of integers, array of
    floats. As like those we have one type of array i.e.
    Arrays of pointer.
   Arrays of pointer will only hold a bunch of
    addresses.
   These addresses may be addresses of arrays or
    may be addresses of different variables.
   As for a integer type array compiler allocates
    sequence of memory to store hold addresses.
   When we create pointer array we have to
    initialize the each element to direct to a
    address.
   The address may be a address of a variable or
    an array. But they must be similar data type
    of pointer array
                    int var1 = 400,var2 = 600;

                    int *arrpo[2];

                    arrpo[0] = &var1;
                    arrpo[1] = &var2;
   We can say it point to pointer. It means we can
    hold the address of a pointer as we hold the
    address of the variable.
   So when a pointer points to the address of a
    variable we told it indirection. When another
    pointer points to that pointer which points to a
    variable is called multiple indirection.

                     int var;
                     int *fPointer,**spointer;
                     fpointer = &var;
                     spointer = &fpointer;
Pointer02     Pointer01     variable

  • Address     • Address     • Value
   When we have a pointer to a pointer the
    pointer which will point to variable. We will
    confuse with (*), (**) and (&). So do not
    confuse with these.
                                 var = gives value stored in var
    int var;                    *fpointer = gives value stored in var
    int *fPointer,**spointer;   **spointer = gives value stored in var
    fpointer = &var;
    spointer = &fpointer;
                                *spointer = gives address of fpointer
                                &spointer = gives address of spointer
                                &fpointer = gives address of fpointer
                                &var = gives address of variable
   Even though a function is not a variable, it still
    has a physical location in memory that can be
    assigned to a pointer.
   This address is the entry point of the function
    and it is the address used when the function is
    called.
   Once a pointer points to a function, the function
    can be called through that pointer.
   Function pointers also allow functions to be
    passed as arguments to other functions.

More Related Content

What's hot (20)

Pointers in c++ by minal
Pointers in c++ by minalPointers in c++ by minal
Pointers in c++ by minal
 
Pointer in c++ part3
Pointer in c++ part3Pointer in c++ part3
Pointer in c++ part3
 
c++ pointers by Amir Hamza Khan (SZABISTIAN)
c++ pointers by Amir Hamza Khan (SZABISTIAN)c++ pointers by Amir Hamza Khan (SZABISTIAN)
c++ pointers by Amir Hamza Khan (SZABISTIAN)
 
Pointer in c++ part1
Pointer in c++ part1Pointer in c++ part1
Pointer in c++ part1
 
C pointer
C pointerC pointer
C pointer
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
C programming - Pointer and DMA
C programming - Pointer and DMAC programming - Pointer and DMA
C programming - Pointer and DMA
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
pointers
pointerspointers
pointers
 
Ponters
PontersPonters
Ponters
 
Pointer
PointerPointer
Pointer
 
C pointer basics
C pointer basicsC pointer basics
C pointer basics
 
C Pointers
C PointersC Pointers
C Pointers
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1
 
Pointers
PointersPointers
Pointers
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Introduction to pointers and memory management in C
Introduction to pointers and memory management in CIntroduction to pointers and memory management in C
Introduction to pointers and memory management in C
 
8 Pointers
8 Pointers8 Pointers
8 Pointers
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 

Viewers also liked

Basic array in c programming
Basic array in c programmingBasic array in c programming
Basic array in c programmingSajid Hasan
 
jal hi jivan hai pre prentation
jal hi jivan hai pre prentationjal hi jivan hai pre prentation
jal hi jivan hai pre prentationSatyam Soni
 
One dimensional arrays
One dimensional arraysOne dimensional arrays
One dimensional arraysSatyam Soni
 
Array in c language
Array in c languageArray in c language
Array in c languagehome
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Conceptsthinkphp
 

Viewers also liked (10)

Basic array in c programming
Basic array in c programmingBasic array in c programming
Basic array in c programming
 
Arrays in C
Arrays in CArrays in C
Arrays in C
 
Amazon Web Services
Amazon Web ServicesAmazon Web Services
Amazon Web Services
 
jal hi jivan hai pre prentation
jal hi jivan hai pre prentationjal hi jivan hai pre prentation
jal hi jivan hai pre prentation
 
One dimensional arrays
One dimensional arraysOne dimensional arrays
One dimensional arrays
 
Structures
StructuresStructures
Structures
 
Array in C
Array in CArray in C
Array in C
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Arrays
ArraysArrays
Arrays
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 

Similar to Pointer in c++ part2

Similar to Pointer in c++ part2 (20)

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
 
Lect 9(pointers) Zaheer Abbas
Lect 9(pointers) Zaheer AbbasLect 9(pointers) Zaheer Abbas
Lect 9(pointers) Zaheer Abbas
 
Lect 8(pointers) Zaheer Abbas
Lect 8(pointers) Zaheer AbbasLect 8(pointers) Zaheer Abbas
Lect 8(pointers) Zaheer Abbas
 
Pointers in c language
Pointers in c languagePointers in c language
Pointers in c language
 
Pointer
PointerPointer
Pointer
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Pointers-Computer programming
Pointers-Computer programmingPointers-Computer programming
Pointers-Computer programming
 
PSPC--UNIT-5.pdf
PSPC--UNIT-5.pdfPSPC--UNIT-5.pdf
PSPC--UNIT-5.pdf
 
Pointer introduction day1
Pointer introduction day1Pointer introduction day1
Pointer introduction day1
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Pointer in c
Pointer in c Pointer in c
Pointer in c
 
Pointers
PointersPointers
Pointers
 
PPS-POINTERS.pptx
PPS-POINTERS.pptxPPS-POINTERS.pptx
PPS-POINTERS.pptx
 
SPC Unit 3
SPC Unit 3SPC Unit 3
SPC Unit 3
 
Data structure lecture 1
Data structure   lecture 1Data structure   lecture 1
Data structure lecture 1
 
20.C++Pointer.pptx
20.C++Pointer.pptx20.C++Pointer.pptx
20.C++Pointer.pptx
 
pointers.pptx
pointers.pptxpointers.pptx
pointers.pptx
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.
 
FYBSC(CS)_UNIT-1_Pointers in C.pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptxFYBSC(CS)_UNIT-1_Pointers in C.pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptx
 
Arrays to arrays and pointers with arrays.pptx
Arrays to arrays and pointers with arrays.pptxArrays to arrays and pointers with arrays.pptx
Arrays to arrays and pointers with arrays.pptx
 

More from Subhasis Nayak

More from Subhasis Nayak (18)

Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)Php, mysq lpart5(mysql)
Php, mysq lpart5(mysql)
 
working with database using mysql
working with database using mysql working with database using mysql
working with database using mysql
 
Php, mysq lpart3
Php, mysq lpart3Php, mysq lpart3
Php, mysq lpart3
 
Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)
 
Jsp 01
Jsp 01Jsp 01
Jsp 01
 
Jsp 02(jsp directives)2003
Jsp 02(jsp directives)2003Jsp 02(jsp directives)2003
Jsp 02(jsp directives)2003
 
Php, mysq lpart1
Php, mysq lpart1Php, mysq lpart1
Php, mysq lpart1
 
Php, mysqlpart2
Php, mysqlpart2Php, mysqlpart2
Php, mysqlpart2
 
C:\fakepath\jsp01
C:\fakepath\jsp01C:\fakepath\jsp01
C:\fakepath\jsp01
 
Servlet & jsp
Servlet  &  jspServlet  &  jsp
Servlet & jsp
 
J2ee connector architecture
J2ee connector architectureJ2ee connector architecture
J2ee connector architecture
 
how to create object
how to create objecthow to create object
how to create object
 
C++ arrays part2
C++ arrays part2C++ arrays part2
C++ arrays part2
 
C++ arrays part1
C++ arrays part1C++ arrays part1
C++ arrays part1
 
Introduction to network
Introduction to networkIntroduction to network
Introduction to network
 
Flow control in c++
Flow control in c++Flow control in c++
Flow control in c++
 
Oops And C++ Fundamentals
Oops And C++ FundamentalsOops And C++ Fundamentals
Oops And C++ Fundamentals
 
Text mode Linux Installation Part 01
Text mode Linux Installation Part 01Text mode Linux Installation Part 01
Text mode Linux Installation Part 01
 

Recently uploaded

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 

Recently uploaded (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 

Pointer in c++ part2

  • 2. Pointer assignments  Pointer arithmetic  Pointer comparisons  Pointers & arrays  Arrays of pointers  Multiple indirection  Pointers to function  Dynamic allocations
  • 3. We know how to point a variable .  In this example I will show how to point a variable from two pointers. You must pass the vaddres1 to vAddress2.Because we passed the address of variable to vaddress1 not to vAddress2
  • 4. There are only two arithmetic operations that you may use on pointers: ◦ Addition ◦ Subtraction  But you can do all operation on pointer’s value as: ◦ Addition ◦ Subtraction ◦ Multiplication ◦ division
  • 5. There are two type of comparison of pointers ◦ In between pointer = this is the comparison held between the addresses they hold If (p1>p2) ◦ In between pointer value = here we comparing between the values they hold. If (*p1>*p2)
  • 6.
  • 7.
  • 8. you can direct a pointer to hold the array's address as we do for a normal variable.  As I told you array is a sequence of similar type of data type.  To hold the array's address when you direct the pointer to hold array's address it holds the first’s of that array address only.  To get the address of each element of array we have to add the exact index number of that element. how can we do that? we can do that with help of a loop or directly adding the index’s number.
  • 9. Int array[5]; Int array[5]; Int *Parray; Int *Parray; Parray = array; Parray = &array[0];
  • 10.
  • 11.
  • 12.
  • 13. We already learned array of integers, array of floats. As like those we have one type of array i.e. Arrays of pointer.  Arrays of pointer will only hold a bunch of addresses.  These addresses may be addresses of arrays or may be addresses of different variables.  As for a integer type array compiler allocates sequence of memory to store hold addresses.
  • 14. When we create pointer array we have to initialize the each element to direct to a address.  The address may be a address of a variable or an array. But they must be similar data type of pointer array int var1 = 400,var2 = 600; int *arrpo[2]; arrpo[0] = &var1; arrpo[1] = &var2;
  • 15.
  • 16.
  • 17. We can say it point to pointer. It means we can hold the address of a pointer as we hold the address of the variable.  So when a pointer points to the address of a variable we told it indirection. When another pointer points to that pointer which points to a variable is called multiple indirection. int var; int *fPointer,**spointer; fpointer = &var; spointer = &fpointer;
  • 18. Pointer02 Pointer01 variable • Address • Address • Value
  • 19. When we have a pointer to a pointer the pointer which will point to variable. We will confuse with (*), (**) and (&). So do not confuse with these.  var = gives value stored in var int var; *fpointer = gives value stored in var int *fPointer,**spointer; **spointer = gives value stored in var fpointer = &var; spointer = &fpointer; *spointer = gives address of fpointer &spointer = gives address of spointer &fpointer = gives address of fpointer &var = gives address of variable
  • 20.
  • 21. Even though a function is not a variable, it still has a physical location in memory that can be assigned to a pointer.  This address is the entry point of the function and it is the address used when the function is called.  Once a pointer points to a function, the function can be called through that pointer.  Function pointers also allow functions to be passed as arguments to other functions.