SlideShare ist ein Scribd-Unternehmen logo
1 von 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.

Weitere ähnliche Inhalte

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie Pointer in c++ part2

Ähnlich wie 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
 

Mehr von Subhasis Nayak

Mehr von 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
 

Kürzlich hochgeladen

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
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
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
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
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
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
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
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
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 

Kürzlich hochgeladen (20)

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
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
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
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
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
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
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
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
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 

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.